bot = commands.Bot(command_prefix="!") 类型错误:BotBase.__init__() 缺少一个必需的关键字参数:'intents
我在运行代码后遇到了这个错误:
文件 "C:\BOT Music\BM.py",第 8 行,
bot = commands.Bot(command_prefix="!")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: BotBase.init() 缺少一个必需的关键字参数:'intents'
我尝试了很多 Bard AI 提出的解决方法,但这个错误总是出现。
这是我从 AI Bard 那里复制的代码:
import os
from dotenv import load_dotenv
from googleapiclient.discovery import build
from discord.ext import commands
from discord.utils import get
import discord_py_opus
DISCORD_TOKEN = os.getenv("...")
intents = discord.Intents.default()
intents.voice = True
bot = commands.Bot(command_prefix="!", intents=intents, token=DISCORD_TOKEN)
youtube = build("youtube", "v3", developerKey=os.getenv("DEVELOPER_KEY"))
current_song = None
opus = discord_py_opus.OpusEncoder()
@bot.event
async def on_ready():
print(f"Logged in as {bot.user}")
....
bot.run()`
我希望这个问题能得到解决。
1 个回答
0
Bard 知道的东西很有限。使用 AI 后,记得查看文档,因为 AI 容易出现错误。
我无法测试你的代码或重现错误,因为获取 Discord 令牌的过程有点复杂。
我还注意到你代码末尾有一个多余的反引号(`),这是 AI 比较喜欢放在代码示例末尾的,因为代码通常出现在 markdown 块中。这个也应该去掉。
我知道这不是一个完整的答案,但在这种情况下,这是我能提供的最好建议。