我在用python编写的discord bot中使用了slap命令。有人能告诉我如何用机会类型ID代替ping吗?

2024-06-16 00:14:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我使这个命令只能通过ping使用,但我不知道如何添加使用成员ID的机会

以下是我已经拥有的代码:

@Bot.command()
async def slap( ctx, member : discord.Member ):
    emb = discord.Embed(title=None, description = f"For the whole chat there was a noise from a {ctx.author.mention} slap {member.mention} in the face!", color=0x3498db)
    await ctx.send( embed = emb )

Tags: the代码命令idbot成员pingcommand
2条回答

我有一个密码,当你提到某人而不是使用他们的ID时,它会打耳光

@client.command()
@commands.cooldown(1, 2, commands.BucketType.user)
async def slap(ctx, member:discord.User=None):
  if (member == ctx.message.author or member == None):
      await ctx.send(f"{ctx.message.author.mention} slaps themselves!") 
  else:
      await ctx.send(f"{ctx.message.author.mention} slaps {member.mention}!")  

您可以使用guild.get_member(ID)来执行此操作

顺便说一句,您的命令也应该与全名#标记一起使用,比如slap AZ#0573,而不是提及

@Bot.command()
async def slap(ctx, member_id:int):
    member = ctx.guild.get_member(member_id)
    emb = discord.Embed(title=None, description = f"For the whole chat there was a noise from a {ctx.author.mention} slap {member.mention} in the face!", color=0x3498db)
    await ctx.send( embed = emb )

enter image description here

相关问题 更多 >