Home > Net >  How to get around "TypeError: 'coroutine' object is not callable"
How to get around "TypeError: 'coroutine' object is not callable"

Time:01-10

This is currently the code I have right now

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")

Currently the issue I have is that when I call the function "help_utilities" which returns the error stated in the title, is there any way I can call the function and do the action inside the function "help_utilities" with the argument "utils"?

CodePudding user response:

You wrote

        help_utilities()

You wanted to instead call

        help_utilities(ctx)

When reporting a diagnostic error message, it would be extremely helpful to paste in the full stack trace.

CodePudding user response:

Sorry for the vague question without the full error details, the way I got around this issue is changing the function to a asynchronous function and called them using await with the parameter of "ctx" as stated by user @J_H

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)

and

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