【问题标题】:How to print a list of guild members?如何打印公会成员列表?
【发布时间】:2021-05-01 15:25:03
【问题描述】:

代码如下:

@bot.command()
async def test(ctx):
    for member in ctx.message.guild.members:
        print(member.name)

结果:Discord Bot

如何让它打印公会中的每个成员,包括机器人?

(我的版本是3.7.3)

【问题讨论】:

  • 你需要启用intents.members
  • 无视,谢谢!

标签: discord.py python-3.7


【解决方案1】:

您需要在 bot 设置中启用“Privileged Gateway Intents”:Discord Developer Portal

import discord
from discord.ext import commands

intents=intents=discord.Intents.all()
bot = commands.Bot('!',intents=intents)

@bot.event
async def on_ready():
    print("Bot is Online!")

@bot.command()
async def members(ctx):
    member = ctx.guild.members
    for member in member:
        print(member.name)

bot.run("TOKEN")

【讨论】:

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