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

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

為什么on_message停止命令工作?

為什么on_message停止命令工作?

楊__羊羊 2019-07-31 11:02:50
為什么on_message停止命令工作?基本上,一切似乎工作正常并啟動,但由于某種原因我不能調用任何命令。我一直在尋找一個小時,看著示例/觀看視頻,我不能為我的生活弄清楚出了什么問題。代碼如下:import discordimport asynciofrom discord.ext import commands bot = commands.Bot(command_prefix = '-')@bot.event async def on_ready():     print('Logged in as')     print(bot.user.name)     print(bot.user.id)     print('------')@bot.event async def on_message(message):     if message.content.startswith('-debug'):         await message.channel.send('d')@bot.command(pass_context=True)async def ping(ctx):     await ctx.channel.send('Pong!')@bot.command(pass_context=True)async def add(ctx, *, arg):     await ctx.send(arg)我在on_message中的調試輸出實際上工作并響應,并且整個機器人運行沒有任何異常,但它只是不會調用命令。
查看完整描述

1 回答

?
蕪湖不蕪

TA貢獻1796條經驗 獲得超7個贊

從重寫文檔:

覆蓋提供的默認值以on_message禁止運行任何額外命令。要解決此問題,請bot.process_commands(message)在您的結尾添加一行on_message。例如:

@bot.event
async def on_message(message):
    # do some extra stuff here

    await bot.process_commands(message)

默認on_message包含對此協同程序的調用,但是當您使用自己的協程覆蓋它時on_message,您需要自己調用它。


查看完整回答
反對 回復 2019-07-31
  • 1 回答
  • 0 關注
  • 596 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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