【问题标题】:How to get a discord bot to output everything user inputs instead of just the first input?如何让不和谐机器人输出用户输入的所有内容,而不仅仅是第一个输入?
【发布时间】:2019-06-20 10:34:33
【问题描述】:

我正在尝试让机器人重复用户输入的内容,重复用户指定的次数。
我遇到的问题是,如果用户输入:!repeat 5 x y,机器人只会重复x 5 次,而不是x y 5 次。

这是我要运行的代码:

@bot.command()
async def repeat(times: int, content="Repeating..."):
    for i in range(times):
        if times > 10:
            await bot.say("Cannot spam more than 10 messages at a time.")
            return
        else:
            await bot.say(content)

【问题讨论】:

    标签: python discord repeat discord.py python-3.7


    【解决方案1】:

    您可以使用 keyword-only argument syntax 并执行类似的操作

    @bot.command()
    async def repeat(times: int, *,content="Repeating..."):
      for i in range(times):
        if times > 10:
          await bot.say("Cannot spam more than 10 messages at a time.")
          return
        else:
          await bot.say(content)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-22
      • 2018-03-17
      • 2021-12-31
      • 2021-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多