【问题标题】:discord.py - channel.members not giving members in a channeldiscord.py - channel.members 不给频道中的成员
【发布时间】:2020-12-19 17:54:41
【问题描述】:

对于一个命令,我试图将每个成员从特定类别中的每个频道移动到另一个频道,并删除该类别中的所有频道。我已经测试了代码,除了channel.members 部分之外,它都可以正常工作。 print(channel.members) 每次运行命令时都会返回一个空列表 []。知道我做错了什么吗?

我知道获取公会 ID 会阻止此操作,但我没有在代码中的任何地方这样做。

#Delete all channels in Ongoing Matches
@client.command()
async def comm(ctx):
    general = discord.utils.get(ctx.guild.channels, name='Vibing')
    category = discord.utils.get(ctx.guild.categories, name='Ongoing Matches')
    channels = category.channels
    for channel in channels:
        print(channel.members)
        for member in channel.members:
            print(member)
            await member.move_to(general)
        await channel.delete()

【问题讨论】:

  • 您要删除文字频道还是语音频道?
  • 您使用的是什么版本的 discord.py?如果是 1.5.0,请查看意图 here

标签: python discord.py


【解决方案1】:

这都是关于 discord.Intents() 前往您的开发者门户 > 您的项目 > Bot 并打开“服务器成员意图”。然后在您的项目中将意图添加到您的机器人中

# create intents before creating bot/client instance
intents = discord.Intents().default()
intents.members = True
# create the instance
client = discord.Client(intents=intents)

如果您使用 discord.ext.commands.Bot,过程类似,只需在构造函数中添加 intents=intents。

【讨论】:

    猜你喜欢
    • 2020-12-01
    • 1970-01-01
    • 2020-12-21
    • 2021-02-27
    • 2021-09-01
    • 2021-06-06
    • 2018-10-09
    • 1970-01-01
    • 2021-09-15
    相关资源
    最近更新 更多