我遇到了一个问题,我无法回复带有嵌入的消息。 这甚至可能吗?我猜是这样,我只是做错了。
我的错误 - TypeError: 对象方法不能用于 'await' 表达式
if message.content.startswith('!test'):
await message.reply
embedVar = discord.Embed(description=".order", color=0x7289da)
embedVar.add_field(name='test', value='test')
await message.channel.send(embed=embedVar)
答案 0 :(得分:0)
您没有正确使用 reply
函数。您不能单独拥有它,就像您在代码中使用 await message.reply
所做的那样。
# on_message event, the way you have done it
if message.content.startswith('!test'):
await message.reply("This is a test!")
# or if you prefer the commands extension (recommended)
@bot.command()
async def test(ctx):
await ctx.reply("This is a test!")
# you can also make it so it doesn't mention the author
await ctx.reply("This is a test!", mention_author=False)
# Note that both of the code in the commands example can be used in your on_message event
# as long as you remember to change ctx to message
以上代码已经过测试,如下图所示。
关于嵌入回复,我发现如果机器人只是用嵌入回复,它可能不会提到作者。
embed = discord.Embed(description="This is a test", color=0x123456)
await message.reply(embed=embed)
上面的代码如下图所示。
答案 1 :(得分:0)
看看discord.py
API Reference,应该是可以的。请注意,Message.reply()
是一个方法,而不是一个属性。文档描述了该方法:
abc.Messageable.send()
回复消息的快捷方式。
该方法采用位置参数 content
和关键字参数 kwargs
,它们对应于 TextChannel.send()
方法的关键字参数。由于 embed
是关键字参数之一,因此它也是 reply()
之一。
if message.content.startswith('!test'):
embed = discord.Embed(description=".order", color=0x7289da)
embed.add_field(name="test", value="test")
await message.reply(embed)
顺便说一句,我建议使用 discord.ext.commands
框架而不是使用 on_message()
和字符串方法。
答案 2 :(得分:0)
试试这个:
embed=discord.Embed(title="Tile",
description="Desc", color=0x00ff00)
embed.add_field(name="Fiel1", value="hi", inline=False)
embed.add_field(name="Field2", value="hi2", inline=False)
await self.bot.say(embed=embed)
`