简体   繁体   中英

Discord.py kick command not working with no error message

So this kick command that I coded worked and then it didn't after work after I made an embed any idea why? Here is the code

#KICK COMMAND
@bot.command()
@commands.has_permissions(administrator=True)
async def kick(ctx, user : discord.Member,*,reason):
  
  kickbed = discord.Embed(title="Kick Log",description=f"Kicked by {ctx.author}.", color=23457535)
 
  kickbed.add_field(name="User Kicked:", value=f'{user}',inline=False)
 
  kickbed.add_field(name="Reason:", value=f'{Reason}',inline=False)
  
  await user.kick(reason=reason)
  await ctx.send(embed=kickbed)

First, you used variable reason , but then in:

kickbed.add_field(name="Reason:", value=f'{Reason}',inline=False)

You used the variable Reason (uppercase first letter), which is not defined. You just have to change it to reason .

Then you used 23457535 as a color, which is incorrect because the value you pass to the color= should be less than or equal to 16777215 .

discord.Colour in docs


As stated by @NikkieDev :

It could be because you're trying to mention a user that is not in the server.

When I tested it works (mentioning while a user is not on the server), but if you want you could send the message first and then kick the user:

await ctx.send(embed=kickbed) # changed the order of last 2 lines
await user.kick(reason=reason)

It could be because you're trying to mention a user that is not in the server. Therefore it cannot mention the user.

Try this instead:

from discord.ext import commands
import discord
@commands.has_permissions(administrator=True)
    async def kick(self, ctx, member: discord.Member, reason="No reason given"):
        kickDM=discord.Embed(title='Kicked', description=(f"You've been kicked from {member.guild.name} for {reason} by {ctx.author}"))
        kickMSG=discord.Embed(title='Kicked', description=(f"{member} has been kicked from {member.guild.name} for {reason} by {ctx.author}"))
        await member.send(embed=kickDM)
        await ctx.send(embed=kickMSG)
        await member.kick(reason=reason)
bot.add_command(kick)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM