I create a bot in discord, but the function does not work because of the lack of arguments state and data

Viewed 40

I'm new to python and have taken on the task of creating a discord bot. Everything is going well, except for the function to kick the participant out. The code doesn't work because this function has no state and data arguments. I would be very grateful if someone could help.

import discord 
from discord.ext import commands

config = {
    'prefix': '.',
}

intents = discord.Intents().all()

bot = commands.Bot(command_prefix=config['prefix'], intents=intents)

@bot.event

async def on_member_join(member):
    await member.send('Привет! Добро пожаловать на наш сервер!')

@bot.command

async def kick(ctx, user : discord.User(), *arg, reason='Причина не указана'):
    await bot.kick(user)
    await ctx.send('Участник {user.name} был изгнан из сервера по причине "{reason}"')

bot.run(config['token'])

This is error that python returns:

Traceback (most recent call last):
  File "d:\Python\Projects\Discord\Revanius\main.py", line 20, in <module>
    async def kick(ctx, user : discord.User(), *arg, reason='Причина не указана'):
TypeError: BaseUser.__init__() missing 2 required keyword-only arguments: 'state' and 'data'
PS D:\Python\Projects\Discord\Revanius> 

Help me please!

2 Answers

The issue is

user: discord.User()

You're supposed to add a type annotation, but you're annotating it by creating an instance. Remove the round brackets () at the end of it.

If you want to read up on type annotations: https://peps.python.org/pep-0484/

Compare this to other languages, like for example Java:

User user = ... // This is correct
new User() user = ... // This makes no sense
Related