temp84323
temp84323

Reputation: 62

How can you make a bot in discord.py send a certain message a specified number of times

I'm trying to make my bot send a certain message a certain number of times. For example, you could do .say hello 5 and it would send "hello" 5 times. This is my code for the say command:

@has_permissions(manage_messages=True)
async def say(ctx, *, message=None):
    message = message or "you have to make it say something"
    message_components = message.split()
    await ctx.message.delete()
    await ctx.send(message)

Upvotes: 1

Views: 548

Answers (3)

Cohen
Cohen

Reputation: 2415

@client.command()
@commands.has_permissions(manage_messages=True)
async def say(ctx,  amount=1, *, message=None):
    if message == None:
        await ctx.send('You must provide a message to say!')
        return
    await ctx.message.delete()
    for i in range(amount):
        await ctx.send(message)

Upvotes: 1

Nurqm
Nurqm

Reputation: 4743

You have to pass a new parameter for the amount of messages. Then, you can send messages in for loop. Also, you don't have to do message = message or "something". You can replace message=None with message="something".

@has_permissions(manage_messages=True)
async def say(ctx,  amount=1, *, message="you have to make it say something"):
    message_components = message.split()
    await ctx.message.delete()
    for i in range(0, amount):
        await ctx.send(message)

Upvotes: 1

Netore Mining
Netore Mining

Reputation: 55

in python if it is a string you can add a *5 in order to give the meaning of "repeat string 5 times"

Upvotes: 1

Related Questions