簡體   English   中英

每個用戶可以使用一次命令嗎?

[英]Can a command be used once per user?

我正在制作(高級)嵌入創建命令。 基本上,您鍵入的任何內容都將顯示為嵌入。 長話短說,我告訴我的朋友測試它是否有任何錯誤。 他嘗試的第一件事是在不實際使用的情況下運行完全相同的命令。 我的意思是什么? 好吧,他只是鍵入/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 多行,但基本上是一樣的,有更多的回報等。

您可以使用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

將允許您的用戶同時運行一次命令。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM