Home > OS >  Discord.py kick slash command not working
Discord.py kick slash command not working

Time:12-18

@slash.slash(
    name="kick",
    description="Kick a member",
    guild_ids=[guildids],
    options=[
        create_option(
            name="user",
            description="The user I should kick",
            required=True,
            option_type=6
            ),
        create_option(
            name="reason",
            description="Why should I kick them?",
            required=False,
            option_type=3
            )
        ]
)
@has_permissions(kick_members=True)
async def _kick(ctx:SlashContext, user:str, reason:str="None Given"):
    reason = str(reason)
    usr = "<@" str(user.id) ">"
    await user.kick(reason)
    await user.send("Kicked from " ctx.guild.name " for " reason)
    embed = discord.Embed(title="Kicked a user", description="Kicked " usr " for reason: " reason)
    await ctx.send(embed=embed)
    print(ctx.author.name " used: kick")


# ERRORS
@_kick.error
async def kick_error(ctx:SlashContext, error):
    if isinstance(error, MissingPermissions):
        embed = discord.Embed(title="Permission Error")
        embed.add_field(name="Missing:", value="Kick Members")
        await ctx.send(embed=embed)

When I do /kick user reason nothing happend, it just gives the interaction failed. It doesnt even kick the user or send a message to them saying they where kicked. I have no idea what is going on because of my little experience.

CodePudding user response:

Don’t use user:str. It converts user to string but you can not kick str object. Just write user instead of user:str.

Also note that it is better to use user.mention instead of "<@" str(user.id) ">" and read about string formatting in python.

CodePudding user response:

Discord.py is now deprecated and there is no guarantee it will work or not in 2022. I could suggest you to shift to some other discord library or move to Javascript as it support / commands.

Here is the original post of discord.py discontinued: https://gist.github.com/Rapptz/4a2f62751b9600a31a0d3c78100287f1/

  • Related