【问题标题】:Python/Discord: Prevent only certain people from accessing a commandPython / Discord:仅阻止某些人访问命令
【发布时间】:2020-09-08 14:32:56
【问题描述】:

我正在为 Discord RPG 设置角色创建器,并且我编写了一些代码,如果有人已经在启动角色创建器,我会阻止它:

if message.content == "MMO start":
    if not currentcreator == 0:
        await message.channel.send("Someone is already making a profile so please wait")
    currentcreator = message.author

但是我不知道如何在不取消第一人称的情况下阻止第二个人继续前进?

【问题讨论】:

  • 尝试使用布尔值来检查它是否被使用,甚至为所有函数调用维护一个日志(在一定时间后删除以存储)
  • 我能详细说明一下吗?

标签: python discord discord.py


【解决方案1】:

试试这个:

character_creating = False

@bot.event
async def on_message(message):
    if message.content == "MMO start":
        if character_creating:
            await message.channel.send("Someone is already making a profile so please wait")
            return
        character_crearing = True
        

        #then do the character creating code here and at last do
        character_creating = False

【讨论】:

    猜你喜欢
    • 2023-03-24
    • 2012-05-31
    • 1970-01-01
    • 1970-01-01
    • 2010-10-13
    • 2013-12-26
    • 1970-01-01
    • 2021-07-27
    • 1970-01-01
    相关资源
    最近更新 更多