【问题标题】:Discord.py kick command not working with no error messageDiscord.py kick 命令无法正常工作且没有错误消息
【发布时间】:2021-12-09 17:42:54
【问题描述】:

此 kick 命令有效,但添加嵌入后无效。知道为什么吗?

#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)

【问题讨论】:

    标签: python discord.py pycord


    【解决方案1】:

    首先,您使用了变量reason,然后在:

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

    您使用了未定义的变量Reason(首字母大写)。您只需将其更改为reason

    然后您使用23457535 作为颜色,这是不正确的,因为您传递给color= 的值应该小于或等于16777215

    discord.Colour in docs


    @NikkieDev所述:

    可能是因为您试图提及不在服务器中的用户。

    当我测试它工作时(当用户不在服务器上时提及),但如果你愿意,你可以先发送消息然后踢用户:

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

    【讨论】:

      【解决方案2】:

      这可能是因为您试图提及不在服务器中的用户。因此它不能提及用户。

      试试这个:

      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)
      

      【讨论】:

      • OP 没有提到用户。当discord.Userdiscord.Member 对象转换为字符串时,您会得到<username>#<discriminator>
      • 另外,您可以提及在您发送消息的服务器之外的用户。
      猜你喜欢
      • 2021-06-23
      • 2013-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-21
      • 1970-01-01
      相关资源
      最近更新 更多