I moved the kick function and the kick error handler from the main function to a cog but now it throws an error
Main File
from discord import client
from discord.ext import commands
import discord
from dotenv import load_dotenv
import os
load_dotenv()
TOKEN = os.getenv('token')
client = commands.Bot(command_prefix=".")
@client.event
async def on_ready():
print(f"Initialised as {client.user}")
# loading the cogs
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
client.load_extension(f'cogs.{filename[:-3]}')
client.run(TOKEN)
Cog
import discord
from discord.ext import commands
class Moderation(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print('Moderation is online')
@commands.command()
async def kick(ctx, member : discord.Member = None, *, reson=None):
if member is None:
await ctx.reply("Usage: .kick @user reason", mention_author=False)
else:
await member.kick(reason=reson)
await ctx.reply("done",mention_author=False)
# This stopped working
#------------------------
@kick.error()
async def kick_error(ctx, error):
if isinstance(error, commands.errors.MemberNotFound):
await ctx.reply("Member not found", mention_author=False)
#------------------------
def setup(client):
client.add_cog(Moderation(client))
Error message: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: Moderation.kick_error() takes 2 positional arguments but 3 were given