Python 机器人在更新后停止响应消息 discord.py

Python bot stopped responding to messages after updating discord.py

我使用命令 pip install -U git+https://github.com/Rapptz/discord.py

更新了 discord.py

在此之后,我收到错误 TypeError: BotBase.__init__() missing 1 required keyword-only argument: 'intents'

然后我用client = commands.Bot(command_prefix="!", intents=discord.Intents.default())

替换了client = commands.Bot(command_prefix="!")

那里的代码 运行,但我的命令 none 没有得到任何响应。这是我的一些代码(即使我删除了所有其他命令,代码也不起作用):

from discord.ext import commands
from dhooks import Embed
import discord
import asyncio
from discord.ui import Button, View


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

token = "tokenhere"

@client.event
async def on_ready():
    channel = client.get_channel([test server channel ID])
    await channel.send("I'm online!")
    print("Bot is ready!")

@client.command(brief = "Returns 'pong' if the bot is online and provides the latency")
async def ping(ctx):
    await ctx.send(f'Pong! That took {round(client.latency * 1000)}ms!')

client.run(token)

请务必注意,“我在线”已由我的测试服务器中的机器人成功发送。

我不确定如何解决这个错误。

您需要明确启用 message_content 意图(以及在 Discord 开发者页面上为您的机器人启用相应的开关)才能立即接收所有消息:

intents = discord.Intents.default()
intents.message_content = True
client = commands.Bot(command_prefix="!", intents=intents)

有关详细信息,请参阅 the discord.py docs