Discord.py sudo all 命令没有响应

时间:2021-03-11 18:13:18

标签: python discord.py

这可能需要一些解释。我做了一个命令,sudo 是一个叫 p!sudo [member.mention] [message] 的人。它是这样工作的:

@client.command()
async def sudo(ctx, member: discord.Member, *, message=None):
    await ctx.message.delete()
    webhooks = await ctx.channel.webhooks()
    for webhook in webhooks:
        await webhook.delete()
    webhook = await ctx.channel.create_webhook(name=member.name)
    await webhook.send(str(message),
                       username=member.name,
                       avatar_url=member.avatar_url)

现在,我想发出另一个命令,即 sudo 是服务器中的每个人。这是我得到的:

@client.command()
async def sudoall(ctx, *, message=None):
  for member in ctx.guild.member:
    webhooks = await ctx.channel.webhooks()
    for webhook in webhooks:
        await webhook.delete()
    webhook = await ctx.channel.create_webhook(name=member.name)
    await webhook.send(str(message),
                       username=member.name,
                       avatar_url=member.avatar_url)

但是,我收到此错误消息:

Ignoring exception in command sudoall:
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "main.py", line 34, in sudoall
    for member in ctx.guild.member:
AttributeError: 'Guild' object has no attribute 'member'

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

Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 859, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Guild' object has no attribute 'member'

1 个答案:

答案 0 :(得分:2)

使用 ctx.guild.members 获取属于公会的成员列表