【问题标题】:Discord.py returning users name without using the on-message function?Discord.py 在不使用消息功能的情况下返回用户名?
【发布时间】:2021-03-30 04:42:10
【问题描述】:

我最近开始改进我的不和谐机器人,不使用 on_message 函数加上一长串 if 语句,但现在我已经开始使用 @bot.command(name=" ") 如果我尝试使用 message.author 它没有'没有要检查作者的消息。我该如何解决这个问题?

@bot.command(name="start")
async def some_crazy_function_name(ctx):
        if not currentcreator == 0:
                await message.channel.send("Someone is already making a profile, 
                please wait")
                currentcreater = message.author
                dir = r'C:\\Users\\User\Desktop\DiscordMMO\User-Profiles'
                MessageAuthor = str(message.author)
                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 create

【问题讨论】:

  • 您能提供您正在使用的代码的 sn-p 吗?
  • 编辑到帖子中
  • 如果我在这里错了,请纠正我,但您还没有定义 message 变量?您也可以使用ctx.author 来获取作者。也可以直接使用ctx.send()回复。文档中的更多信息here

标签: python discord discord.py


【解决方案1】:

这是更新的代码,如果你很懒,我不建议复制。

@bot.command(name="start")
async def some_crazy_function_name(ctx):
        if currentcreator != 0:
                await ctx.send("Someone is already making a profile, 
                please wait")
                currentcreater = ctx.author
                dir = r'C:\\Users\\User\Desktop\DiscordMMO\User-Profiles'
                MessageAuthor = str(ctx.author)
                ProfileDIR = os.path.join(dir,MessageAuthor)
                doesExist = os.path.exists(ProfileDIR)
               if doesExist == False:
                   embed=discord.Embed(title="Creating Profile", description=f"{MessageAuthor}, your profile is being created.")
                   await ctx.send(embed=embed)

完成了。

【讨论】:

    【解决方案2】:

    ctx 是您的命令。 例如,图片中您有很多方法。

    ctx.作者 |命令作者

    ctx.channel.guild |公会。

    查看文档。

    但您要的是 ctx.author

    【讨论】:

      猜你喜欢
      • 2022-08-06
      • 2023-02-23
      • 1970-01-01
      • 2018-09-24
      • 2017-12-14
      • 1970-01-01
      • 2020-11-08
      • 1970-01-01
      • 2011-07-25
      相关资源
      最近更新 更多