我知道我做错了什么,因为我复制了 Discord 给我们的示例代码(在 discord 的快速入门网站上找到的第一个代码块)但我似乎找不到问题所在。
我正在运行的代码: (是的,我知道导入不应该直接运行代码......我只是想测试最基本的代码,但我无法让它工作💀💀💀)
import discord
from config import __BOTTOKEN__ as __TOKEN__
intents = discord.Intents.default()
intents.message_content = True # this is where the error happens even when the bot has admin privs
# if I remove this line, I won't be able to read messages from other users
# in more complex versions of this code
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$hello'):
await message.channel.send('Hello!')
client.run(__TOKEN__)
我遇到的错误:
2024-03-14 18:34:51 INFO discord.client logging in using static token
Traceback (most recent call last):
File "/home/runner/Discord-bot/main.py", line 9, in <module>
main()
File "/home/runner/Discord-bot/main.py", line 4, in main
import example
File "/home/runner/Discord-bot/example.py", line 21, in <module>
client.run(__TOKEN__)
File "/home/runner/Discord-bot/.pythonlibs/lib/python3.10/site-packages/discord/client.py", line 860, in run
asyncio.run(runner())
File "/nix/store/8w6mm5q1n7i7cs1933im5vkbgvjlglfn-python3-3.10.13/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/nix/store/8w6mm5q1n7i7cs1933im5vkbgvjlglfn-python3-3.10.13/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "/home/runner/Discord-bot/.pythonlibs/lib/python3.10/site-packages/discord/client.py", line 849, in runner
await self.start(token, reconnect=reconnect)
File "/home/runner/Discord-bot/.pythonlibs/lib/python3.10/site-packages/discord/client.py", line 778, in start
await self.connect(reconnect=reconnect)
File "/home/runner/Discord-bot/.pythonlibs/lib/python3.10/site-packages/discord/client.py", line 704, 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.
起初我认为我的机器人的 discord 开发门户中的权限可能需要更高,所以我将其设置为管理员,因为这将获得所有权限......但我得到了相同的消息。
任何见解或建议将不胜感激!
起初我认为我的机器人的不和谐开发门户中的权限可能需要更高,所以我将其设置为管理员,因为这将获得所有权限......但我得到了相同的消息。