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

函數式編程
TA貢獻1807條經驗 獲得超9個贊
你應該使用get_context
@client.event async?def?on_message(message): ????ctx?=?await?client.get_context(message)

蝴蝶不菲
TA貢獻1810條經驗 獲得超4個贊
通過使用異步函數,你是否await在函數中使用過,
@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
添加回答
舉報
0/150
提交
取消