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

Question:

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)
Asked By: Spago

||

Answers:

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)
Answered By: Tristo
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.