【问题标题】:My spam command doesn't work when the message has spaces当邮件有空格时,我的垃圾邮件命令不起作用
【发布时间】:2021-05-25 01:32:18
【问题描述】:

我的信息是(Hello World!)

和命令(/spam Hello World)

还有终端:(对不起,我不能复制粘贴它,因为我的终端不能复制它)

我的代码:

    @commands.command(description="you want spam but you slow typing? use this command")
async def spam(self, ctx, messages, amount : int):
  limit = 30
  print(f'bot spam amount : "{amount}" msg : "{message}"')
  if amount > limit:
    await ctx.send('spam count exceeded the limit (30)')
    print('not spamming')
  else:
    print('spamming')
    for _ in range(amount):
      await ctx.send(message)

【问题讨论】:

    标签: python discord.py error-code


    【解决方案1】:

    首先,您的参数变量是messages,但您要打印出message:它们需要同名。其次,如果您的命令在message 之前使用amount 会更理想。你将如何运行它是/spam 5 Hello World,它会打印出Hello World 5 次。要打印出多个单词,只需使用* 作为将接收多单词字符串的变量之前的参数。试试这个:

    @commands.command(description="you want spam but you slow typing? use this command")
    async def spam(self, ctx, amount : int, *, message):
      limit = 30
      print(f'bot spam amount : "{amount}" msg : "{message}"')
      if amount > limit:
        await ctx.send('spam count exceeded the limit (30)')
        print('not spamming')
      else:
        print('spamming')
        for _ in range(amount):
          await ctx.send(message)
    

    【讨论】:

      猜你喜欢
      • 2018-07-14
      • 2016-07-29
      • 2011-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-11
      • 2013-01-05
      相关资源
      最近更新 更多