我当前正在创建一个建议系统,但是我遇到了一个问题,我不知道如何编辑网络挂钩发送的消息(嵌入),这是我的代码:
async def suggestion(ctx):
async with aiohttp.ClientSession() as session:
webhook = Webhook.from_url('...', adapter=AsyncWebhookAdapter(session))
embed = discord.Embed(color=color)
embed.add_field(name="Nouvelle suggestion !", value=ctx.message.content.lstrip(f"{prefix}suggest"))
embed.set_footer(text=f"""{ctx.message.author} • {datetime.now().strftime("%d %b %Y %H:%M:%S")}""",
icon_url=str(ctx.message.author.avatar_url))
await webhook.send(embed=embed, username=ctx.author.name, avatar_url=ctx.author.avatar_url)
添加反应:
@bot.event
async def on_message(message):
if message.channel.id == 650397901893140481 and message.author.id not in [296687703851008002, 639138362673987584, 632575363830120448]:
await message.add_reaction("<:yes:710947936372129854>")
await message.add_reaction("<:neutral:710949706296983603>")
await message.add_reaction("<:no:710947944823652362>")
用于编辑消息:
@bot.command()
async def test(ctx, *args):
message = await ctx.channel.fetch_message(args[0])
embed = discord.Embed(color=color)
embed.add_field(name="Nouvelle suggestion !", value=args[1])
await message.edit(embed=embed)
错误:discord.ext.commands.errors.CommandInvokeError:命令引发了异常:禁止:403禁止(错误代码:50005):无法编辑其他用户创作的消息
答案 0 :(得分:0)
为我先前的回答中的错误信息表示歉意。
Webhooks无法编辑消息-它们只能发送消息。这意味着,如果您想给自己编辑一条消息的错觉,则需要删除一条消息,然后使用新内容重新发送。
参考:
discord.Webhook()