Reputation: 11
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
Reputation: 1415
That is happening because you have some mistakes in your code:
@text.error()
should be replaced with @text.error
ctx
and error
in text_error
function{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