【问题标题】:How to get around "TypeError: 'coroutine' object is not callable"如何解决“TypeError:'coroutine' object is not callable”
【发布时间】:2022-01-09 19:00:32
【问题描述】:

这是我现在拥有的代码

def help_utilities(ctx):
    embed = discord.Embed(
        color=discord.Colour.dark_blue()
    )
    embed.set_author(name="help utils")
    embed.add_field(name="Decode", value="Decodes an encrypted message (Base64)")
    embed.add_field(name="Encode", value="Encodes a message in base64")
    embed.add_field(name='Embed', value='Speak through the bot, but with fancy text"', inline=False)
    embed.add_field(name="Add/Subtract/Multiply/Divide", value="Just take two values and do whatever operation with them", inline=False)
    embed.add_field(name="Reverse", value="Reverses your text :/", inline=False)
    embed.add_field(name='Say', value='Speak through the bot!', inline=False)
    author = ctx.message.author
    author.send(embed=embed)

@client.command(pass_context=True)
async def help(ctx, arg=None):
    author = ctx.message.author

    if arg is None:
        embed = discord.Embed(
            color=discord.Colour.gold()
        )
        embed.set_author(name='Help')
        embed.add_field(name="Invite", value="Sends the invite url of the bot lmao", inline=False)
        embed.add_field(name="Disclaimer", value="for the commands below you need to call them like this: .mod \n Basically the second word :sleepy:")
        embed.add_field(name="help mod", value="To see more info on my moderation commands", inline=False)
        embed.add_field(name="help utils", value="To see more info on my utility commands", inline=False)
        embed.add_field(name="help fun", value="My more fun commands :eyes:", inline=False)
        await author.send(embed=embed)
    if (arg == "utils") or (arg == "Utils"):
        help_utilities()
   # there are more If statments like this but right now I will only focus on 1
   # So you can get the idea of whats going on
    else:
        await ctx.send("bro thats not a valid argument")

目前我遇到的问题是,当我调用返回标题中所述错误的函数 "help_utilities" 时,有什么方法可以调用该函数并执行操作在带有参数“utils”的函数“help_utilities”内?

【问题讨论】:

    标签: python python-3.x discord.py


    【解决方案1】:

    你写的

            help_utilities()
    

    你想改为调用

            help_utilities(ctx)
    

    报告诊断错误消息时, 粘贴到完整的堆栈跟踪中会非常有帮助。

    【讨论】:

      【解决方案2】:

      对于没有完整错误详细信息的模糊问题,我很抱歉,我解决此问题的方法是将函数更改为异步函数,并使用用户 @J_H 所述的带有“ctx”参数的 await 调用它们

      async def help_utilities(ctx):
          embed = discord.Embed(
              color=discord.Colour.dark_blue()
          )
          embed.set_author(name="help utils")
          embed.add_field(name="Decode", value="Decodes an encrypted message (Base64)")
          embed.add_field(name="Encode", value="Encodes a message in base64")
          embed.add_field(name='Embed', value='Sends an embed, written like ".Embed (One word title) (Description)"', inline=False)
          embed.add_field(name="Add/Subtract/Multiply/Divide", value="Just take two values and do whatever operation with them", inline=False)
          embed.add_field(name="Reverse", value="Reverses your text :/", inline=False)
          embed.add_field(name='Say', value='Speak through the bot!', inline=False)
          author = ctx.message.author
          await author.send(embed=embed)
      

      if (arg == "utils") or (arg == "Utils"):
          await help_utilities(ctx)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-18
        • 2018-08-21
        • 2018-03-31
        • 2021-10-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多