【问题标题】:Bot not detecting server members (Discord.py)Bot 未检测到服务器成员 (Discord.py)
【发布时间】:2021-09-03 09:26:01
【问题描述】:

我有一个命令,我为服务器选择一个随机成员,但由于某种原因,每当我运行它时,它只提到它自己.. 好像它无法检测到服务器中除了它自己之外还有其他成员.这是代码: 好的


client = commands.Bot(command_prefix=['%', "v", "V"],
                      case_insensitive=True,
                      help_command=None)


intents = discord.Intents().all()
intents = True

@client.event
async def on_ready():
    print('Bot is Online! ;)')

    servers = len(client.guilds)
    members = 0
    for guild in client.guilds:
        members += guild.member_count - 1

    await client.change_presence(activity=discord.Activity(
        type=discord.ActivityType.watching,
        name=f'{servers} servers and {members} members | %help'))

@client.command()
async def choosemem(ctx):
    guild = ctx.guild
    await ctx.send(f"{random.choice(guild.members).mention} has been chosen")

这是完整的代码,包括状态和意图。

【问题讨论】:

标签: command discord.py member mention


【解决方案1】:

您还需要在 client= commands.Bot 中添加意图值

intents = discord.Intents().all()


client = commands.Bot(command_prefix=['%', "v", "V"],
                      case_insensitive=True,
                      help_command=None,
                      intents = intents)

【讨论】:

  • 是的,我做到了。它仍在返回机器人本身。编辑:我回到开发门户并启用了所有意图。现在可以了,谢谢。如何将此问题标记为已回答?
猜你喜欢
  • 2021-01-21
  • 2022-01-24
  • 2020-11-20
  • 2021-05-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-14
  • 2023-04-08
相关资源
最近更新 更多