简体   繁体   English

不和谐中特定角色的用户列表(Python)

[英]userlist of a specific role in the discord (Python)

I would like to have a command to get a list of ALL users with a special role.我想要一个命令来获取具有特殊角色的所有用户的列表。 But this doesn't really work.但这真的行不通。

Everything is output, but not the members.一切都是输出,但不是成员。 Does anyone here have an idea what this is about?这里有人知道这是关于什么的吗? Or even a better alternative?或者甚至更好的选择?

Many thanks in advance提前谢谢了

import discord
import asyncio
from discord import message
from discord.ext import commands

intents = discord.Intents.all()
client = discord.Client(intents=intents)

class ClansCog(commands.Cog, name='Clans'):
                             
        def __init__(self, bot):
            self.bot = bot
        
        @commands.command(pass_context=True)
        async def deutsch(self, ctx, *args):

            if ctx.channel.type is not discord.ChannelType.private:
                await ctx.message.delete()

            roll_id = 733988944--------
            guild_id = 71911198261------

            guild = self.bot.get_guild(guild_id)
            partner_role = guild.get_role(roll_id)

            print(partner_role.members)
            print(partner_role.id)
            print(client.guilds)
                                         
def setup(bot):
        bot.add_cog(ClansCog(bot))
        print('Clans loaded!')

From Terminal从航站楼

[]
733988944533-------
[]

A friend and I found the problem.我和一个朋友发现了这个问题。 It was an intents problem (thanks Shnap :) )这是一个意图问题(感谢 Shnap :))

bot = commands.Bot(command_prefix='d!'.lower(), case_insensitive=True, intents=intents)

intents=intents was missing, after that no more problem缺少意图=意图,之后就没有问题了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM