我现在正试图为不和创造一个机器人。由于某种原因,令牌给了我这个错误:
2022-11-02 04:42:10 INFO discord.client logging in using static token
Traceback (most recent call last):
File "main.py", line 26, in <module>
client.run(os.getenv("bot_key"))
File "/home/runner/discord-moni-bot-thing/venv/lib/python3.8/site-packages/discord/client.py", line 828, in run
asyncio.run(runner())
File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "/home/runner/discord-moni-bot-thing/venv/lib/python3.8/site-packages/discord/client.py", line 817, in runner
await self.start(token, reconnect=reconnect)
File "/home/runner/discord-moni-bot-thing/venv/lib/python3.8/site-packages/discord/client.py", line 746, in start
await self.connect(reconnect=reconnect)
File "/home/runner/discord-moni-bot-thing/venv/lib/python3.8/site-packages/discord/client.py", line 672, in connect
raise PrivilegedIntentsRequired(exc.shard_id) from None
discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intents instead.
我已经检查了令牌是否与开发人员门户上的令牌相同,而且确实如此。
我已多次更改令牌,并直接用令牌替换os.getenv("bot_key")
。我有另一个机器人,它使用同样的方法,而且效果很好。这是任何人想要的完整代码:( on_message(message)
函数是从我的另一个机器人复制和粘贴的)
import discord
import os
intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print("Logged in as {0.user}".format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith("$hello"):
await message.channel.send("Hello!")
elif message.content.startswith("$dmuser"):
if message.content.find(" "):
if len(message.content.split(" ")) == 2:
await client.get_user(int(message.content.split(" ")[1])).send("You Were Sent A DM By " + str(message.author))
try:
client.run(os.getenv("bot_key")) # <--- THIS HERE
except discord.HTTPException as e:
if e.status == 429:
print("The Discord servers denied the connection for making too many requests")
print("Get help from https://stackoverflow.com/questions/66724687/in-discord-py-how-to-solve-the-error-for-toomanyrequests")
else:
raise e
发布于 2022-11-02 06:39:32
建议转到https://discord.com/developers/applications/并显式地启用应用程序页面中的特权意图。*您从代码中显示的错误的一部分。
问题是您还没有在开发人员门户中启用一些权限,而不是因为令牌。
首先,您进入dev门户并单击BOT,
由于您指定了intents.members = True
,所以需要在门户中启用服务器成员,
因此,只要向下滚动并打开它,您的代码就会正常工作。
https://stackoverflow.com/questions/74284467
复制相似问题