我目前正在開發(fā)一個(gè)機(jī)器人,實(shí)際上已經(jīng)花了更長(zhǎng)的時(shí)間,總是使用命令。命令的參數(shù)始終是上下文對(duì)象:@client.command
async def test(context):
message = context.message所以我圍繞上下文對(duì)象構(gòu)建了整個(gè)系統(tǒng)?,F(xiàn)在我想使用 on_message 事件,但在本例中,Discord 傳遞的是消息對(duì)象,而不是傳遞上下文對(duì)象:@client.event
async def on_message(message):
...如何使用消息對(duì)象獲取上下文對(duì)象?
2 回答

函數(shù)式編程
TA貢獻(xiàn)1807條經(jīng)驗(yàn) 獲得超9個(gè)贊
你應(yīng)該使用get_context
@client.event async?def?on_message(message): ????ctx?=?await?client.get_context(message)

蝴蝶不菲
TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊
通過使用異步函數(shù),你是否await在函數(shù)中使用過,
@client.command
async def test(context):
message = context.message
#This will be stored in context which must be retrieved
@client.event
async def on_message(Message):
ctx = await client.get_context(Message)
#Do whatever you want
添加回答
舉報(bào)
0/150
提交
取消