我试图编辑一个嵌入在另一个频道,例如规则频道.
uprules命令的目的是在不进行另一个嵌入的情况下向前一个嵌入添加一个字段。
我用的是Pycord最新版本。我试过的东西如下。
代码:
import discord
from discord.ext import commands
class Rules(commands.Cog):
def __init__(self, client):
self.client = client
self.Rules = discord.Embed(
title = "__**Test Embed Rules**__",
description = """
Rules
"""
)
@commands.command()
@commands.is_owner()
async def rules(self, ctx):
channel = self.client.get_channel(954750221261373471)
await channel.send(embed=self.Rules)
@commands.command()
async def uprules(self, ctx, number, *, text):
channel = self.client.get_channel(954750221261373471)
msg = await channel.fetch_message(955501538766381066)
Rules.add_field(
name="||Test Embed||\n",
value=f"```css\n[{number}] {text}\n```",
inline=False
)
await msg.edit(embed=self.Rules)
def setup(client):
client.add_cog(Rules(client))错误:
Command raised an exception: AttributeError: type object 'Rules' has no attribute 'add_field'我所看到的:https://docs.pycord.dev/en/master/api.html?highlight=message%20id#discord.Message.id
这就是我试过的。我想我可以使用消息ID来编辑嵌入,但我不知道具体是如何编辑的。任何帮助都是非常感谢的。
谢谢。
发布于 2022-03-21 12:59:41
我认为这种方法根本行不通。我以前从未见过它起作用,也在文档中找不到它的条目。
为了编辑消息,您需要使用await调用直接获取消息。
如下所示:
channel = self.client.get_channel(954750221261373471)
msg = await channel.fetch_message(5389540224354334)对于嵌入错误,应该将变量移动到__init__函数,以便在不阻塞的情况下在任何地方使用它。就像这样:
def __init__(self, client):
self.client = client
self.Rules = discord.Embed(
title = "__**Test Embed Rules**__",
description = "")之后,您是否可以使用变量self.Rules进行所需的嵌入。
资料来源
https://stackoverflow.com/questions/71547719
复制相似问题