【问题标题】:Discord bot doesnt respondDiscord 机器人没有响应
【发布时间】:2021-05-25 04:44:49
【问题描述】:

这是我第一次制作 Discord 机器人。我已经按照教程的每个步骤进行操作,但我的机器人对 !test 命令没有反应。我确实在不和谐服务器中看到了机器人。请帮忙

This is my first time making a discord bot. I've followed every step of the tutorial but my bot doesnt react to the !test command. I do see the bot in the discord server. please help

【问题讨论】:

标签: python python-3.x discord discord.py


【解决方案1】:

首先,在第 15 行,if(message.content.startswith(!test): 的 if 语句位于返回之后。机器人永远不会到达那些线。您将不得不将缩进向后移动(python 中的缩进很烦人)。

if message.author == client.user:
    return
    
if message.content.startswith('!test'):
    await message.channel.send("Hello!")
await client.process_commands(message)

其次,await client.process_commands(message) 仅适用于命令客户端,不适用于基本 discord.Client()。客户必须是这样的

from discord.ext import commands
client = commands.Bot(command_prefix="!")

请参阅What are the differences between Bot and Client? 了解 discord.Client() 和 commands.Bot() 之间的区别。

【讨论】:

    猜你喜欢
    • 2023-02-10
    • 2021-03-11
    • 2022-11-27
    • 2022-10-24
    • 2021-02-01
    • 2022-12-15
    • 2019-08-14
    • 2021-04-21
    相关资源
    最近更新 更多