我正在尝试在我的(第一个)机器人中编写一条命令,该命令会在不和谐频道中打印所有成员 在某个@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
答案 0 :(得分:0)
问题是您正在调用实际的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
将是不和谐成员列表