【问题标题】:Discord bot not responding or listening to commandsDiscord bot 不响应或不听命令
【发布时间】:2022-10-23 17:54:06
【问题描述】:

我刚刚重新访问了一些旧的不和谐机器人代码,很明显它不起作用。 下面的代码要大得多,但即使我将其缩小为导入模块、设置客户端前缀、on_ready(),最后是 client.command(),机器人也不会听或响应。

import discord
from discord.ext import  commands, tasks
client = commands.Bot(command_prefix = '!!')

@client.command(name="ping")
async def ping(ctx):
    print('listening')
    await ctx.send('Pong! '+str(round(client.latency * 1000))+'ms')

client.run(my token)

现在,我在这里听'!! ping' 或 '!!ping' (我尝试同时输入) 如果机器人正在监听这个命令,它至少应该将listening 打印到我的终端中。如果是这样,它应该向我的不和谐频道发送一条消息。

然而,这些都没有发生。

注意:如下所示的就绪功能打印Bot is ready。此外,在不和谐的情况下,我可以看到该机器人在线。

#Connect Bot
@client.event
async def on_ready():
    change_status.start()
    print('Bot is ready')

【问题讨论】:

标签: python discord discord.py


【解决方案1】:

通过执行此操作为您的代码启用意图,这应该可以解决您的问题。

intents = discord.Intents.default()
intents.members = True



client = commands.Bot(command_prefix="!!", intents=intents)

确保在您的 Discord 开发门户上启用 Intent,this 将向您展示如何操作。

【讨论】:

    【解决方案2】:

    我认为客户非常有限和混乱,
    您可以尝试将其切换到机器人吗?

    你的代码:

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

    新代码

    bot = commands.Bot(command_prefix='!')
    

    此外,如果您将其更新到 2.0,您还需要意图

    【讨论】:

    • 你只是改变了一个变量名,这根本没有任何区别......而且他是已经在使用 commands.Bot 而不是 discord.Client…………
    猜你喜欢
    • 2020-12-15
    • 2021-08-28
    • 2021-02-17
    • 2023-03-09
    • 2021-04-17
    • 2021-10-23
    • 2020-12-22
    相关资源
    最近更新 更多