首先,很抱歉混淆了标题,但我不知道如何更准确地称呼它。
因此,我的问题是:我有用于从先前消息中获取discord.Embed对象的代码:
嵌入式的创建:
channel = bot.get_channel(780735930579288115)
embed = discord.Embed(title="December 2020", color=0x6687ff)
embed.set_author(name="New theme voting")
embed.add_field(name="\u200b", value="Nothing Interesting atm", inline=False)
sent = await channel.send("@.everyone We're starting new voting", embed=embed)
config[str(ctx.message.guild.id)]['quiz'] = str(ctx.sent.id)
with open('config.ini', 'w') as configfile:
config.write(configfile)获取嵌入对象:
config.read("config.ini")
uzenet = await ctx.fetch_message(int(config[str(ctx.message.guild.id)]['quiz']))
embed = uzenet.embeds[0]
await ctx.send(embed=embed)错误:
有一个奇怪的错误说discord.Embed对象不是discord.Embed对象(我猜?)
Traceback (most recent call last):
File "C:\Users\user\PycharmProjects\CoronaBot\venv\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:/Users/user/PycharmProjects/CoronaBot/bot.py", line 476, in newOption
await ctx.send(embed=embed)
AttributeError: type object 'Embed' has no attribute 'from_data'我不知道我还能做些什么让python像对待discord.Embed对象一样对待它
发布于 2020-11-24 15:43:32
我认为您需要编写sent.id而不是ctx.sent.id:
channel = bot.get_channel(780735930579288115)
embed = discord.Embed(title="December 2020", color=0x6687ff)
embed.set_author(name="New theme voting")
embed.add_field(name="\u200b", value="Nothing Interesting atm", inline=False)
sent = await channel.send("@.everyone We're starting new voting", embed=embed)
config[str(ctx.message.guild.id)]['quiz'] = str(sent.id) # Here
with open('config.ini', 'w') as configfile:
config.write(configfile)如果您仍然有任何错误,请提供更多的代码,因为这是所有我可以找到的样本,您提供。
发布于 2020-11-24 16:03:45
我假设ctx.sent.id是指消息id,您应该使用ctx.message.id
https://stackoverflow.com/questions/64989717
复制相似问题