首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Discord.py - Bot令牌失败

Discord.py - Bot令牌失败
EN

Stack Overflow用户
提问于 2022-11-02 04:50:03
回答 1查看 97关注 0票数 0

我现在正试图为不和创造一个机器人。由于某种原因,令牌给了我这个错误:

代码语言:javascript
运行
复制
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)函数是从我的另一个机器人复制和粘贴的)

代码语言:javascript
运行
复制
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
代码语言:javascript
运行
复制
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-02 06:39:32

建议转到https://discord.com/developers/applications/并显式地启用应用程序页面中的特权意图。*您从代码中显示的错误的一部分。

问题是您还没有在开发人员门户中启用一些权限,而不是因为令牌。

首先,您进入dev门户并单击BOT,

由于您指定了intents.members = True,所以需要在门户中启用服务器成员,

因此,只要向下滚动并打开它,您的代码就会正常工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74284467

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档