В настоящее время я пытаюсь создать бота для Discord. По какой-то причине токен выдает мне эту ошибку:
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






Рекомендуется перейти на https://discord.com/developers/applications/ и явно включить привилегированные намерения на странице вашего приложения. *Часть ошибки, которую вы показали из кода.
Проблема в том, что вы не включили некоторые разрешения на портале разработчиков не из-за TOKEN.
Сначала вы заходите на портал разработчиков и нажимаете BOT,
так как вы указали intents.members = True,
вам нужно включить намерение участников сервера на портале,
Так что просто прокрутите вниз и включите это, и ваш код должен работать нормально.