【问题标题】:Ping command not working in Discord.py botPing 命令在 Discord.py 机器人中不起作用
【发布时间】:2020-11-21 22:02:48
【问题描述】:

我刚开始制作一个不和谐的机器人,我试图让它使用事件响应 ping,但我读到正确的方法是使用命令,所以我也尝试过,但我的机器人不会响应前缀+'ping '在频道上。终端上没有任何错误或任何东西,但它只是在应该响应时没有响应。我真的很感谢任何帮助,因为我真的不知道我做错了什么,我附上了我开始使用的代码,它具有 ping 的方法,只是事件有效而命令无效,我不知道为什么。当我运行代码时,我还在块中附加了我的机器人在频道上的响应。

import discord
from discord.ext import commands
token = 'NzM4DNc3MDI5OTA4ODA3NzMy.XyMeVA.8oopIfcva4IFuhJwO7pkFXy9j7g'
client = commands.Bot(command_prefix='.')


@client.event
async def on_message(message):
    channel = message.channel
    if message.content.startswith('..ping'):
        await channel.send('pong..')


@client.command(pass_context=True)
async def ping(ctx):
    await ctx.send('pong.')

client.run(token)

南迪尼今天 11:00

.ping

..ping

balalala BOT 今天 11:01

乒乓球..

【问题讨论】:

    标签: python frameworks discord discord.py chatbot


    【解决方案1】:

    当您定义一个事件时,您将覆盖内置的默认事件。on_message() 的默认事件中包含 bot.process_commands(message),它允许您调用您可能猜到的命令。 你看到我在这里得到了什么,你需要添加一个
    等待 bot.process_commands(消息)
    添加 on_message 事件的结尾。

    另外,请更改您的令牌,任何人都可以使用它登录您的机器人。
    如果您需要更多帮助,我还建议加入 discord.py discord 支持服务器,因为它们通常非常活跃并且可以立即回答您的问题。这是邀请:https://discord.gg/r3sSKJJ

    【讨论】:

    • 非常感谢...也不要担心这是一个更改的令牌
    • 没问题 :) 祝你好运
    猜你喜欢
    • 1970-01-01
    • 2019-07-23
    • 2023-03-20
    • 2021-10-06
    • 2022-01-10
    • 2020-07-09
    • 2018-05-04
    • 2020-11-27
    • 2014-09-30
    相关资源
    最近更新 更多