Reputation: 105
I was making a (Advanced) Embed Creation Command. Basically whatever you type will be shown as an embed. Long story short, I told my friend to test it out for any bugs. First thing he tried was to run the exact same command without actually using it. What I mean by that? Well he just typed /createembed
for about x amount of times. The bot started to respond in every call that was made and it basically ended up spamming:
I think now it is a bit easier to understand what I mean. Anyways any idea how can I stop that by telling the bot that a user can use this exact command only once per user?
@commands.command()
async def cad(self, ctx, channel : discord.TextChannel = None):
def check(message):
return message.author == ctx.author and message.channel == ctx.channel
aPP = ctx.author.avatar_url
if not channel:
await ctx.channel.send(f"**{ctx.author}** | Waiting for an Advanced Embed Title. If you wish to cancel this action, just type `Cancel`.")
title = await self.client.wait_for("message", check=check)
if title.content.lower() == "cancel" or title.content.upper() == "Cancel":
await ctx.channel.send(f'**{ctx.author}** | Action has been canceled.')
return
else:
await ctx.send(f"**{ctx.author}** | Waiting for an Advanced Embed Description. If you wish to cancel this action, just type `Cancel`.")
desc = await self.client.wait_for('message', check=check)
if desc.content.lower() == "cancel" or desc.content.upper() == "Cancel":
await ctx.channel.send(f'**{ctx.author}** | Action has been canceled.')
return
else:
await ctx.send(f"**{ctx.author}** | Waiting for an Advanced Embed Author Text. If you wish to skip this type `Skip` otherwise if you want to cancel this action, just type `Cancel`.")
authortext = await self.client.wait_for('message', check=check)
if authortext.content.lower() == "cancel" or authortext.content.upper() == "Cancel":
await ctx.channel.send(f'**{ctx.author}** | Action has been canceled.')
return
It has like 500 more lines but it's basically the same thing with more returns etc.
Upvotes: 0
Views: 400
Reputation: 306
You can use this decorator from discord.ext.commands.
For example :
from discord.ext import commands
@commands.command()
@commands.max_concurrency(number=1, per=commands.BucketType.user, wait=False)
async def cad(self, ctx):
#your command
Will allow your user to run the command once simultaneously.
Upvotes: 3