Reputation: 21
I tried to make a kick command, everything works except when the command is run, the user specified will not be kicked.
@bot.tree.command(name='kick', description='Kicks a user from the server [S]')
async def embed(interaction : discord.Interaction, user : discord.Member, reason : str = None):
permissions = interaction.user.guild_permissions
is_admin = permissions.kick_members
kick = user.guild.kick
if is_admin == True:
embed = discord.Embed(title='Kick Command', color=discord.Color.blurple(), description='Kicks a user.')
embed.set_author( name = f'{interaction.user}', icon_url= f'{interaction.user.display_avatar}')
await kick
embed.add_field(name = 'Username', value=str(user.mention), inline=True)
embed.add_field(name = 'Reason', value=str(reason), inline=True)
embed.add_field(name = 'Moderation', value='User kicked successfully.', inline=True)
embed.set_footer(text="Command called by: {}".format(interaction.user))
embed.set_image(url='image')
await interaction.response.send_message(embed = embed)
I tried the code above and it didn't work, all the code works as expected except that.
Upvotes: 1
Views: 58
Reputation: 55
Try using this, and work your way from there:
The command should be !kick @user reason for kick
import discord
from discord.ext.commands import Bot
from discord.ext import commands
bot= commands.Bot(command_prefix='!', intents=discord.Intents.all())
#adjust intents appropriately for your bot
@commands.command()
@commands.has_permissions(kick_members=True)
async def kick(ctx, member: discord.Member, *, reason=None):
await bot.kick(member)
await ctx.channel.send(f'User {member} has been kicked')
Upvotes: 0