我正在制作一个(高级)嵌入创建命令。基本上,您输入的任何内容都将显示为嵌入内容。长话短说,我告诉我的朋友测试它是否有任何错误。他尝试的第一件事是在不实际使用的情况下运行完全相同的命令。我的意思是什么?好吧,他只是输入了 /createembed
大约 x 次。机器人开始在每次拨打的电话中做出响应,最终以垃圾邮件告终:
我想现在更容易理解我的意思了。无论如何,我知道如何通过告诉机器人用户每个用户只能使用一次这个确切的命令来阻止它?
@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
它有大约 500 多行,但基本上是一样的,返回更多等等。
答案 0 :(得分:3)
您可以使用 this decorator from discord.ext.commands。
例如:
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
将允许您的用户同时运行一次命令。