亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從 on_message 事件中獲取 Discord 上下文對象?

如何從 on_message 事件中獲取 Discord 上下文對象?

jeck貓 2023-07-27 16:17:23
我目前正在開發一個機器人,實際上已經花了更長的時間,總是使用命令。命令的參數始終是上下文對象:@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)


查看完整回答
反對 回復 2023-07-27
?
蝴蝶不菲

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


查看完整回答
反對 回復 2023-07-27
  • 2 回答
  • 0 關注
  • 189 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號