如何修复应该在不和谐服务器中发送垃圾邮件的命令

How do I fix my command that is supposed to spam a message in a discord server

我正在尝试制作一个只有特定角色才能使用的垃圾邮件命令,但是当我 运行 我的代码出现一堆错误时

代码:

@bot.command()
@commands.has_any_role('The Great Mountain Chicken', 'The Great Frogs', 'The Great Toads')
async def spam(ctx, member):
    for i in range(20):
        await ctx.send(f'{member} why do you do this to me. IT BURNS')

错误:

Ignoring exception in command spam:
Traceback (most recent call last):
  File "C:\Users\Jude\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\Jude\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 851, in invoke
    await self.prepare(ctx)
  File "C:\Users\Jude\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 786, in prepare
    await self._parse_arguments(ctx)
  File "C:\Users\Jude\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 697, in _parse_arguments
    transformed = await self.transform(ctx, param)
  File "C:\Users\Jude\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 542, in transform
    raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: member is a required argument that is missing.

您定义了 member 个参数,您需要在调用命令时指定该参数 (!spam <member>)

如果你想获取发出命令的用户(消息的作者),你需要从上下文中获取它(ctx):

@commands.has_any_role(...)
@bot.command()
async def spam(ctx):
    for _ in range(20):
        await ctx.send(f"{ctx.author.mention} why do you do this to me. IT BURNS")