Skip to content
Advertisement

How do I reference “*args” in a discord bot’s code as a message for the bot to send?

This is my code:

@client.command()
async def repeat(*args):
    output = ''
    for word in args:
        output += str(word)
        output += " "
    await client.say(output)

client.say(output) does not work, but I tried to do it in this form: await message.channel.send(output) However, I don’t know what to put for message as my function’s parameter is *args Is there a something else I can put as the message?

Advertisement

Answer

Firstly, you need to have a parameter for your command so that context can be passed to it, this is ctx in this case. client.say() is not what you want to use anymore. I’ve changed your code a bit, hopefully this helps.

@client.command()
async def repeat(ctx, *args):
    await ctx.send(' '.join(args))
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement