【问题标题】:Discord bot using discord.py command not working.PLZDiscord bot 使用 discord.py 命令不起作用.PLZ
【发布时间】:2021-01-02 06:48:36
【问题描述】:

我刚开始学习如何在 discord.py 中编写自己的机器人。但是,我遵循了 Youtube 上的教程,使用了完全相同的代码,但它在我的服务器上不起作用。

import discord from discord.ext import commands


client = commands.Bot(command_prefix = '.')

@client.command(pass_context = True)
async def test(ctx):
    await ctx.send('Pong!')

@client.event
async def on_ready():
    print('Bot is ready')

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    if message.content.startswith('hello'):
        await message.channel.send('Hello there.')

@client.event
async def on_member_join(member):
    print(f'{member}has joined the server!!')

@client.event
async def on_member_remove(member):
    print(f'Seeya,{member}. Oh wait\n can we?')



client.run('NzU1MjI2Mzk1MjM5Nzc2Mjg2.XGGNZA.s2qLVQMONMLqs1f8Zky9wtM6ZDo')

【问题讨论】:

    标签: bots discord.py


    【解决方案1】:

    覆盖默认提供的on_message 禁止运行任何额外的命令。要解决此问题,请在 on_message 末尾添加 client.process_commands(message) 行。

    @client.event
    async def on_message(message):
        if message.author == client.user:
            return
        if message.content.startswith('hello'):
            await message.channel.send('Hello there.')
        
        await client.process_commands(message)
    

    Why does on_message make my commands stop working?

    【讨论】:

      猜你喜欢
      • 2020-08-16
      • 2019-07-23
      • 1970-01-01
      • 2020-09-24
      • 2021-01-05
      • 2020-08-07
      • 2021-05-26
      • 2018-09-17
      • 2021-04-16
      相关资源
      最近更新 更多