【问题标题】:Scraping members ids from a guild, and putting them on a list从公会中获取成员 ID,并将其放在列表中
【发布时间】:2021-07-01 00:21:55
【问题描述】:

我正在尝试执行一个返回公会中所有成员 ID 的命令,到目前为止我一直在这样做:

themembers = []
@client.command()
async def getids(ctx):
    guild = ctx.guild
    for members in guild.members:
        try:
            themembers.append(members.id)
        except:
            pass
    print(themembers)

但是这段代码只给了我机器人帐户的 ID;我该如何解决这个问题?

【问题讨论】:

标签: python discord discord.py


【解决方案1】:

确保在您的 application 中启用 Intents

import discord
from discord.ext import commands
from discord.utils import get

intents = discord.Intents.all()
intents.members = True
bot = commands.Bot(command_prefix=("!"), case_insensitive=True, guild_subscriptions=True, intents=intents)

@bot.event
async def on_ready():
    member_list = []
    for guild in bot.guilds:
        for member in guild.members:
            member_list.append({member.name:member.id})
    print(member_list)

【讨论】:

    【解决方案2】:

    试试看:

    @bot.event
    async def on_ready():
        print(list(mab(lambda i: i.id, bot.get_all_members())))
    

    【讨论】:

      猜你喜欢
      • 2019-12-29
      • 2020-11-21
      • 1970-01-01
      • 1970-01-01
      • 2020-11-11
      • 2018-09-16
      • 1970-01-01
      • 1970-01-01
      • 2013-12-13
      相关资源
      最近更新 更多