我正在尝试在 discord.py 中进行嵌入,但它总是抛出 'await' 外部函数的错误

I am trying to make an embed in discord.py but it always throws an error that 'await' outside function

当一个用户提到另一个用户时,我试图发出拥抱命令,但它显示语法错误 'await' is outside function

代码如下:

    @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 = "comforting isn't it <3", 
            color = 0x83B5E3
        )
        embed.set_image(url='https://tenor.com/N4Sj.gif')
        await ctx.channel.send(embed=embed)

您的代码似乎有几个问题。

首先是缩进问题,其次是您需要使用 \.

转义 '

尝试以下操作:

       async def hug(ctx, member):
          username = ctx.message.author.display_name
          embed = discord.Embed(title = (f'{username} has sent a hug to {member}!'), 
                         description = ('comforting isn\'t it <3'), color = 0x83B5E3)
          image = ('https://tenor.com/N4Sj.gif')
          embed.set_image(url=image)
          await ctx.channel.send(embed=embed)