guild.members not working correctly discord.py(guild.members 无法正常工作 discord.py)
问题描述
我正在尝试使用 discord.py
我的代码是:
@client.command()
async def members(ctx):
members = ctx.guild.members
for member in members:
await ctx.send(member.name)
await ctx.send("done")
但问题是它只发送机器人的名称.如果您弄清楚代码中的问题是什么,那么您能帮帮我吗,我想要所有成员的名字.
But the problem is it's sending the name of the bot only. If you figure out what's the problem in the code then can you pls help me, I want the name of all members.
推荐答案
我给你一个简单的答案,让你很好理解.
i'll give you a brief answer, so that you can understand very well.
在某种程度上,意图与权限相同
intents are as same as permissions, in a way
那么它们有什么用?如果您想在服务器中发生某些事件,则需要意图.有些可以仅通过脚本启用,有些意图如 presence 和 members需要进入 discord 开发者门户并手动启用 + 在脚本中启用
so what is their use? intents are required if you wanna get certain events happening in server. some can be enabled just by the script, and some intents like presence and members require going to discord developer portal and manually enabling + enabling in script
所以您只需打开脚本并转到顶部,添加以下行:
so you just open your script and go to top, add these lines:
from discord.ext import commands
intents = discord.Intents(messages=True, members=True)
client = commands.Bot(command_prefix=commands.when_mentioned_or('prefix_here'), intents=intents)
它正在使用命令,但您也可以将它与 discord.client
方法一起使用,这可以通过..
it is using commands, but you can also use this with the discord.client
method too, which can be done by..
import discord
intents = discord.Intents.all()
client = discord.Client(intents=intents)
现在您尝试使用这些运行您的脚本:)
now you try to run your script with these :)
这篇关于guild.members 无法正常工作 discord.py的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:guild.members 无法正常工作 discord.py


基础教程推荐
- 对多索引数据帧的列进行排序 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01