【发布时间】:2020-11-01 17:24:03
【问题描述】:
我已经创建了一个代码,它发送一个拥抱命令的 gif 并指定它的对象,但是,我还想让它成为可选的提及成员。
当前代码是:
@client.command()
async def hug(ctx, member):
username = ctx.message.author.display_name
embed = discord.Embed(title = (f'{username} has sent a hug to {member}!'), description = ('warm, fuzzy and comforting <3'), color = 0x83B5E3)
image = random.choice([(url1), (url2),....(url10)])
embed.set_image(url=image)
await ctx.channel.send(embed=embed)
我想更改它,以便如果作者使用该命令并且没有提及该成员,该命令仍然有效,而是发送其中一个 gif。我必须创建一个 if 语句吗?
另外,如果可能的话,我该如何更改它,以便像使用作者的显示名称一样使用会员的显示名称?
我尝试过这样做,但它不起作用:
@client.command()
async def hug(ctx, member):
username = ctx.message.author.display_name
name = member.display_name
embed = discord.Embed(title = (f'{username} has sent a hug to {name}!'), description = ('warm, fuzzy and comforting <3'), color = 0x83B5E3)
image = random.choice([(url1), (url2),...(url10)])
embed.set_image(url=image)
await ctx.channel.send(embed=embed)
提前感谢您的帮助
【问题讨论】:
标签: python bots discord discord.py discord.py-rewrite