PageSourceSearch

https://nonebot.dev/assets/js/11e55d40.098e6ecd.js

js nonebot.dev collected 2026-10-03 23:18:28 UTC 5,518 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunknonebot=self.webpackChunknonebot||[]).push([["2669"],{45292(e,t,n){n.r(t),n.d(t,{metadata:()=>s,default:()=>l,frontMatter:()=>r,contentTitle:()=>i,toc:()=>p,assets:()=>c});var s=JSON.parse('{"id":"appendices/session-state","title":"\u4F1A\u8BDD\u72B6\u6001","description":"\u4F1A\u8BDD\u72B6\u6001\u4FE1\u606F","source":"@site/docs/appendices/session-state.md","sourceDirName":"appendices","slug":"/appendices/session-state","permalink":"/docs/next/appendices/session-state","draft":false,"unlisted":false,"editUrl":"https://github.com/nonebot/nonebot2/edit/master/website/docs/appendices/session-state.md","tags":[],"version":"current","lastUpdatedBy":"pre-commit-ci[bot]","lastUpdatedAt":1789135437000,"sidebarPosition":3,"frontMatter":{"sidebar_position":3,"description":"\u4F1A\u8BDD\u72B6\u6001\u4FE1\u606F","options":{"menu":[{"category":"appendices","weight":40}]}},"sidebar":"tutorial","previous":{"title":"\u4F1A\u8BDD\u63A7\u5236","permalink":"/docs/next/appendices/session-control"},"next":{"title":"\u4F7F\u7528\u5E73\u53F0\u63A5\u53E3","permalink":"/docs/next/appendices/api-calling"}}'),a=n(62540),o=n(43023);let r={sidebar_position:3,description:"\u4F1A\u8BDD\u72B6\u6001\u4FE1\u606F",options:{menu:[{category:"appendices",weight:40}]}},i="\u4F1A\u8BDD\u72B6\u6001",c={},p=[];function d(e){let t={a:"a",code:"code",h1:"h1",header:"header",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(t.header,{children:(0,a.jsx)(t.h1,{id:"\u4F1A\u8BDD\u72B6\u6001",children:"\u4F1A\u8BDD\u72B6\u6001"})}),"\n",(0,a.jsx)(t.p,{children:"\u5728\u4E8B\u4EF6\u5904\u7406\u6D41\u7A0B\u4E2D\uFF0C\u548C\u7528\u6237\u4EA4\u4E92\u7684\u8FC7\u7A0B\u5373\u662F\u4F1A\u8BDD\u3002\u5728\u4F1A\u8BDD\u4E2D\uFF0C\u6211\u4EEC\u53EF\u80FD\u9700\u8981\u8BB0\u5F55\u4E00\u4E9B\u4FE1\u606F\uFF0C\u4F8B\u5982\u7528\u6237\u7684\u91CD\u8BD5\u6B21\u6570\u7B49\u7B49\uFF0C\u4EE5\u4FBF\u5728\u4F1A\u8BDD\u4E2D\u7684\u4E0D\u540C\u9636\u6BB5\u8FDB\u884C\u5224\u65AD\u548C\u5904\u7406\u3002\u8FD9\u4E9B\u4FE1\u606F\u90FD\u53EF\u4EE5\u5B58\u50A8\u4E8E\u4F1A\u8BDD\u72B6\u6001\u4E2D\u3002"}),"\n",(0,a.jsxs)(t.p,{children:["NoneBot \u4E2D\u7684\u4F1A\u8BDD\u72B6\u6001\u662F\u4E00\u4E2A\u5B57\u5178\uFF0C\u53EF\u4EE5\u901A\u8FC7\u7C7B\u578B ",(0,a.jsx)(t.code,{children:"T_State"})," \u6765\u83B7\u53D6\u3002\u5B57\u5178\u5185\u53EF\u4EE5\u5B58\u50A8\u4EFB\u610F\u7C7B\u578B\u7684\u6570\u636E\uFF0C\u4F46\u662F\u8981\u6CE8\u610F\u7684\u662F\uFF0CNoneBot \u672C\u8EAB\u4F1A\u5728\u4F1A\u8BDD\u72B6\u6001\u4E2D\u5B58\u50A8\u4E00\u4E9B\u4FE1\u606F\uFF0C\u56E0\u6B64\u4E0D\u8981\u4F7F\u7528 ",(0,a.jsx)(t.a,{href:"/docs/next/api/consts",children:"NoneBot \u4F7F\u7528\u7684\u952E\u540D"}),"\u3002"]}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-python",children:'from nonebot.typing import T_State\n\n\[email protected]("key", prompt="\u8BF7\u8F93\u5165\u5BC6\u7801")\nasync def _(state: T_State, key: str = ArgPlainText()):\n    if key != "some password":\n        try_count = state.get("try_count", 1)\n        if try_count >= 3:\n            await matcher.finish("\u5BC6\u7801\u9519\u8BEF\u6B21\u6570\u8FC7\u591A")\n        else:\n            state["try_count"] = try_count + 1\n            await matcher.reject("\u5BC6\u7801\u9519\u8BEF\uFF0C\u8BF7\u91CD\u65B0\u8F93\u5165")\n    await matcher.finish("\u5BC6\u7801\u6B63\u786E")\n'})}),"\n",(0,a.jsx)(t.p,{children:"\u4F1A\u8BDD\u72B6\u6001\u7684\u751F\u547D\u5468\u671F\u4E0E\u4E8B\u4EF6\u5904\u7406\u6D41\u7A0B\u76F8\u540C\uFF0C\u5728\u671F\u95F4\u7684\u4EFB\u4F55\u4E00\u4E2A\u4E8B\u4EF6\u5904\u7406\u51FD\u6570\u90FD\u53EF\u4EE5\u8FDB\u884C\u8BFB\u5199\u3002"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-python",children:'from nonebot.typing import T_State\n\n\[email protected]()\nasync def _(state: T_State):\n    state["key"] = "value"\n\n\[email protected]()\nasync def _(state: T_State):\n    await matcher.finish(state["key"])\n'})}),"\n",(0,a.jsxs)(t.p,{children:["\u4F1A\u8BDD\u72B6\u6001\u8FD8\u53EF\u4EE5\u7528\u4E8E\u53D1\u9001\u52A8\u6001\u6D88\u606F\uFF0C\u6D88\u606F\u6A21\u677F\u5728\u53D1\u9001\u65F6\u4F1A\u4F7F\u7528\u4F1A\u8BDD\u72B6\u6001\u5B57\u5178\u8FDB\u884C\u6E32\u67D3\u3002\u6D88\u606F\u6A21\u677F\u7684\u4F7F\u7528\u65B9\u6CD5\u5DF2\u7ECF\u5728",(0,a.jsx)(t.a,{href:"/docs/next/tutorial/message#%E4%BD%BF%E7%94%A8%E6%B6%88%E6%81%AF%E6%A8%A1%E6%9D%BF",children:"\u6D88\u606F\u5904\u7406"}),"\u4E2D\u4ECB\u7ECD\u8FC7\uFF0C\u8FD9\u91CC\u4E0D\u518D\u8D58\u8FF0\u3002"]}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-python",children:'from nonebot.typing import T_State\nfrom nonebot.adapters import MessageTemplate\n\n\[email protected]()\nasync def _(state: T_State):\n    state["username"] = "user"\n\n\[email protected]("password", prompt=MessageTemplate("\u8BF7\u8F93\u5165 {username} \u7684\u5BC6\u7801"))\nasync def _():\n    await matcher.finish(MessageTemplate("\u5BC6\u7801\u4
1E3A {password}"))\n'})})]})}function l(e={}){let{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(d,{...e})}):d(e)}},43023(e,t,n){n.d(t,{R:()=>r,x:()=>i});var s=n(63696);let a={},o=s.createContext(a);function r(e){let t=s.useContext(o);return s.useMemo(function(){return"function"==typeof e?e(t):{...t,...e}},[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:r(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.