Discord Bot can only see itself and no other users in guild(Discord Bot 只能看到自己,不能看到公会中的其他用户)
问题描述
我最近一直在关注本教程来获取我自己是从 Discord 的 API 开始的.不幸的是,当我得到打印公会中所有用户的部分时,我碰壁了.
I have recently been following this tutorial to get myself started with Discord's API. Unfortunately, when I got the part about printing all the users in the guild I hit a wall.
当我尝试打印所有用户的名称时它只打印机器人的名称,没有其他内容.作为参考,公会总共有六个用户.该机器人具有管理员权限.
When I try to print all users' names it only prints the name of the bot and nothing else. For reference, there are six total users in the guild. The bot has Administrator privileges.
import os
import discord
TOKEN = os.environ.get('TOKEN')
client = discord.Client()
@client.event
async def on_ready():
for guild in client.guilds:
print(guild, [member.name for member in guild.members])
client.run(TOKEN)
推荐答案
从 discord.py v1.5.0 开始,您需要为您的机器人使用 Intents,您可以通过以下方式了解更多信息点击这里换句话说,您需要在代码中进行以下更改 -
As of discord.py v1.5.0, you are required to use Intents for your bot, you can read more about them by clicking here
In other words, you need to do the following changes in your code -
import discord
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = os.getenv('DISCORD_GUILD')
intents = discord.Intents.all()
client = discord.Client(intents=intents)
@client.event
async def on_ready():
for guild in client.guilds:
if guild.name == GUILD:
break
print(
f'{client.user} is connected to the following guild:
'
f'{guild.name} (id: {guild.id})'
)
# just trying to debug here
for guild in client.guilds:
for member in guild.members:
print(member.name, ' ')
members = '
- '.join([member.name for member in guild.members])
print(f'Guild Members:
- {members}')
client.run(TOKEN)
这篇关于Discord Bot 只能看到自己,不能看到公会中的其他用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Discord Bot 只能看到自己,不能看到公会中的其他
基础教程推荐
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 包装空间模型 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
