So I have done tons of research, found many answers, but none of them worked. I am trying to get my bot to kick a user on command, but I don’t know the proper syntax. Help would be appreciated, thanks.
intents = discord.Intents.all()
intents.members = True
bot = commands.Bot(command_prefix='#', intents=intents)
@bot.event
async def on_message(message):
if '#kick' in message.content.lower():
mod=discord.utils.get(message.author.guild.roles, name='Mod')
if mod in message.author.roles:
await message.channel.send('Who do you want to kick?')
try:
message=await bot.wait_for('message', check=lambda m: m.author==message.author and m.channel==message.channel, timeout=15)
except asyncio.TimeoutError:
await message.channel.send('Your victim got away')
else:
member2id=message.mentions[0].id
member2=await bot.fetch_user(member2id)
await member2.kick()
await message.channel.send(f'{message.content} was kicked')
else:
await message.channel.send('You dont have the permission to use that command')
bot.run('token')
>Solution :
I believe you’re looking for Member.kick, as opposed to User.kick (which does not exist).
I believe message.mentions returns a list of Member objects, so the snippet might be:
intents = discord.Intents.all()
intents.members = True
bot = commands.Bot(command_prefix='#', intents=intents)
@bot.event
async def on_message(message):
if '#kick' in message.content.lower():
mod=discord.utils.get(message.author.guild.roles, name='Mod')
if mod in message.author.roles:
await message.channel.send('Who do you want to kick?')
try:
message=await bot.wait_for('message', check=lambda m: m.author==message.author and m.channel==message.channel, timeout=15)
except asyncio.TimeoutError:
await message.channel.send('Your victim got away')
else:
await message.mentions[0].kick()
await message.channel.send(f'{message.content} was kicked')
else:
await message.channel.send('You dont have the permission to use that command')
bot.run('token')
However, note that Message.mentions can be empty, and that the list is randomly ordered.
Alternatively, discord.py supports more kick functions, see them here.