How to get a discord bot to output everything user inputs instead of just the first input?

不想你离开。 提交于 2019-12-11 18:55:54

问题


I'm trying to get a bot that will repeat what a user inputs, as many times as the user specifies.
The issue I'm running into is that if the user types: !repeat 5 x y, the bot will only repeat x 5 times, and not x y 5 times.

This is the code I'm trying to run:

@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)

回答1:


You can use the keyword-only argument syntax and do something like

@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)


来源:https://stackoverflow.com/questions/54384797/how-to-get-a-discord-bot-to-output-everything-user-inputs-instead-of-just-the-fi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!