BiscuitButB
BiscuitButB

Reputation: 11

I am getting an text error ' required positional argument: 'coro' ' while making error handler for one of command in my discord bot

import discord
from discord.ext import commands

class Text(commands.Cog):
  def __init__(self, client):
    self.client = client
  
  @commands.command()
  @commands.has_permissions(administrator=True)
  async def text(self, ctx, *, message):
    await ctx.message.delete()
    await ctx.send(message)
    
  @text.error()
  async def text_error(self, error, ctx):
    if isinstance(error, commands.MissingPermissions):
      await ctx.send(f"{ctx.auhtor.mention} You don't Have permission to use this command")

def setup(client):
  client.add_cog(Text(client))

The whole error:

File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 609, in _load_from_module_spec
    raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.text' raised an error: TypeError: error() missing 1 required positional argument: 'coro'

Upvotes: 1

Views: 72

Answers (1)

loloToster
loloToster

Reputation: 1415

That is happening because you have some mistakes in your code:

  1. @text.error() should be replaced with @text.error
  2. You swaped ctx and error in text_error function
  3. You made a typo in {ctx.auhtor.mention}

Final code:

import discord
from discord.ext import commands


class Text(commands.Cog):
    def __init__(self, client):
        self.client = client

    @commands.command()
    @commands.has_permissions(administrator=True)
    async def text(self, ctx, *, message):
        await ctx.message.delete()
        await ctx.send(message)

    @text.error
    async def text_error(self, ctx, error):
        if isinstance(error, commands.MissingPermissions):
            await ctx.send(
                f"{ctx.author.mention} You don't Have permission to use this command"
            )


def setup(client):
    client.add_cog(Text(client))

Upvotes: 1

Related Questions