【问题标题】:how can I display in the #channel, members with a certain role? (with discord.py)如何在#channel中显示具有特定角色的成员? (与不和谐.py)
【发布时间】:2020-04-02 09:56:53
【问题描述】:

我正在尝试在我的(第一个)机器人中编写一个命令,该命令会在不和谐频道中打印所有成员 在某个@role 中(在这里它被称为“Serf”) 这是我的命令/功能

@client.command()
async def snap(ctx):
    target = discord.Role.members("Serf")
    for person in target:
        await ctx.send(person)

但什么也没发生,我在终端中收到此错误

Ignoring exception in command snap:
Traceback (most recent call last):
  File "/home/thonkpad/.local/lib/python3.7/site-packages/discord/ext/commands/core.py", line 83, in wrapped
    ret = await coro(*args, **kwargs)
  File "Python/thanosBot/bot.py", line 28, in snap
    target = discord.Role.members("Serf")
TypeError: 'property' object is not callable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/thonkpad/.local/lib/python3.7/site-packages/discord/ext/commands/bot.py", line 892, in invoke
    await ctx.command.invoke(ctx)
  File "/home/thonkpad/.local/lib/python3.7/site-packages/discord/ext/commands/core.py", line 797, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/home/thonkpad/.local/lib/python3.7/site-packages/discord/ext/commands/core.py", line 92, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: 'property' object is not callable

【问题讨论】:

标签: python discord discord.py-rewrite


【解决方案1】:

问题是您调用了实际的 discord.Role 对象本身,而没有找到您想要的特定角色的 Role 对象。你可以这样做:

@client.command()
async def snap(ctx):
    role = discord.utils.get(ctx.message.guild.roles, name="Serf")
    target = role.members
    for person in target:
        await ctx.send(person.name)

target 将是一个 discord.Member 对象列表

【讨论】:

    猜你喜欢
    • 2021-05-15
    • 2021-06-19
    • 2020-12-05
    • 2020-10-20
    • 1970-01-01
    • 1970-01-01
    • 2021-02-17
    • 2020-12-05
    • 1970-01-01
    相关资源
    最近更新 更多