每个用户可以使用一次命令吗? [英] Can a command be used once per user?
问题描述
我正在执行(高级)嵌入创建命令.基本上,您键入的任何内容都将显示为嵌入.长话短说,我告诉我的朋友对其进行任何错误测试.他尝试的第一件事是运行完全相同的命令而不实际使用它.我的意思是什么?好吧,他只是键入/createembed
大约x次.该僵尸程序开始对所拨打的每个电话进行响应,并且基本上以垃圾邮件的形式结束了:
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
它多了500行,但是基本上是相同的,但有更多的回报等.
It has like 500 more lines but it's basically the same thing with more returns etc.
推荐答案
您可以使用例如:
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.
这篇关于每个用户可以使用一次命令吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!