Discord.py客户端要求发送提到的用户



我有一个名为p!slap的命令,我希望它能让我的机器人说出{message.author} slapped {message.mention}和一个随机的gif,但我不知道该怎么做。有人能帮忙吗?谢谢

@client.command()
async def slap(ctx, message.mention):
embedVar = discord.embed(title=f"<@{message.author.id}> slapped {message.mention}")
list = [
#gif links and stuff
]
await ctx.channel.send(random.choice(list))```

您的代码有一些问题。

  • 一开始,我不明白你想用命名参数message.mention来做什么,但我想你想做的是";拍打";你提到的负责人。为此,您必须在参数中获取成员对象。然后,你可以提到这个成员。

  • 此外,您不应该定义名为list的变量。这可能会因为内置方法list而导致错误。

  • 另一件事是,不和谐模块没有embed方法,它必须是discord.Embed。你必须注意大写字母。

  • 你从未发送过你定义的嵌入,你必须发送它才能让你的命令工作。

  • 对于最后一个,我不知道lst列表中会有什么,但我想会有文件。如果你要发送一个文件,你不能只发送它。你必须在.send()方法中传递一个参数。但这只适用于文件。如果你只是想发送一个链接,那么你不必传递任何参数。

@client.command()
async def slap(ctx, member: discord.Member):
embedVar = discord.Embed(title=f"{ctx.author.mention} slapped {member.mention}")
lst = [
#gif links and stuff
]
await ctx.channel.send(file=discord.File(random.choice(lst)), embed=embedVar)

最新更新