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

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

Discord.py、bot.event 有效,但 bot.command 無效

Discord.py、bot.event 有效,但 bot.command 無效

ibeautiful 2023-12-12 10:00:08
因此,如果我實現了 bot.event,bot.command 就不起作用,但如果我評論或刪除 bot.event,bot.command 就可以正常工作。在這里,bot.command 不起作用,但 bot.event 起作用:# bot.pyimport osfrom discord.ext import commandsfrom dotenv import load_dotenvload_dotenv()TOKEN = os.getenv('DISCORD_TOKEN')bot = commands.Bot(command_prefix='dedmu ')@bot.eventasync def on_ready():    print(f'{bot.user.name} has connected to Discord!')@bot.eventasync def on_message(message):    if message.author == bot.user:        return    if message.content.lower() == 'testt':        await message.channel.send('it works')@bot.command(name='test')async def test(ctx, arg):    await ctx.send(arg)bot.run(TOKEN)如果我用 bot.event 注釋這兩個函數,則 bot.command 可以完美工作。它出什么問題了?:<
查看完整描述

1 回答

?
BIG陽

TA貢獻1859條經驗 獲得超6個贊

因為你有一個on_message活動。當您的機器人中有on_message事件時,您需要await bot.process_commands(message)在事件代碼的最后一行添加on_message。否則它將阻止命令工作。



查看完整回答
反對 回復 2023-12-12
  • 1 回答
  • 0 關注
  • 153 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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