【问题标题】:Discord.py command not working without any error messages or outputDiscord.py 命令在没有任何错误消息或输出的情况下无法正常工作
【发布时间】:2021-06-23 18:40:21
【问题描述】:

这是直到我今天运行它时该命令没有提供任何反馈、没有嵌入、没有错误消息并且没有新文件时的代码:

@bot.command(name="start")
async def some_crazy_function_name(ctx):
        global currentcreator
        if not currentcreator == 0:
                await message.channel.send("Someone is already making a profile, please wait")
        currentcreater = ctx.author
        dir = r'C:\\Users\\FiercePC\Desktop\DiscordMMO\User-Profiles'
        MessageAuthor = str(ctx.author.id)
        ProfileDIR = os.path.join(dir,MessageAuthor)
        doesExist = os.path.exists(ProfileDIR)
        if doesExist == False:
                embed=discord.Embed(title="Creating Profile", url="", description=MessageAuthor+", your profile is being created", color=0x3b05ff)
                await ctx.send(embed=embed)
                os.makedirs(ProfileDIR,1)
                
                file = os.path.join(ProfileDIR,"Hitpoints.txt")
                open(file,"x")
                openfile = open(file,"w")
                openfile.write("3")
                openfile.close()
                
                file = os.path.join(ProfileDIR,"MaxHitpoints.txt")
                open(file,"x")
                openfile = open(file,"w")
                openfile.write("3")
                openfile.close()
                
                file = os.path.join(ProfileDIR,"HitpointsEXP.txt")
                open(file,"x")
                openfile = open(file,"w")
                openfile.write("0")
                openfile.close()
                
                file = os.path.join(ProfileDIR,"StrengthEXP.txt")
                open(file,"x")
                openfile = open(file,"w")
                openfile.write("0")
                openfile.close()
                
                file = os.path.join(ProfileDIR,"StrengthLevel.txt")
                open(file,"x")
                openfile = open(file,"w")
                openfile.write("1")
                openfile.close()
                
                embed=discord.Embed(title="Profile Created", url='', description=MessageAuthor+', thanks for setting up your profile, now you can enjoy a unique MMO RPG experience only on discord.', color=0x3b05ff)
                await ctx.send(embed=embed)   
                currentcreator = 0

我没有更改任何使它无法正常运行的东西,所以我很困惑为什么输入我的命令前缀 / 然后 start 不会做任何事情。我什至从之前的测试中删除了现有文件,看看它是否只看到现有文件,所以没有发送任何东西,但它仍然不起作用。

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    您是否正在运行 on_message 事件?如果是这样,那可能会使命令不起作用。

    【讨论】:

    • 我没有使用 on_message,我使用的是正确的机器人语法,它只检查带有前缀的消息,使用 on_message 会大大降低你的机器人速度
    • 您提供的代码是唯一不起作用的命令吗?
    • 是的,我测试了我所有的其他命令,它们工作正常
    • 虽然您可能已经这样做了,但请检查以确保其缩进级别不在另一个函数中。另外,第 5 行的“消息”变量来自哪里,因为当我运行它时,它说没有名为消息的变量
    • 消息是 discord python 模块的一部分,不是变量
    【解决方案2】:

    好的,我最终修复了它,事实证明我的电脑是由 Fierce PC 预先构建的,这使得它预先带有 1 个可见的 FiercePC 用户和 1 个隐藏的 FiercePC 用户。代码决定将文件保存给我以前不知道存在的隐藏用户

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-21
      • 2020-12-29
      • 2020-02-25
      • 2013-07-20
      • 2018-09-24
      • 2013-10-14
      • 1970-01-01
      • 2015-01-26
      相关资源
      最近更新 更多