Reputation: 62
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
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
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
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