discord.Embed 未被视为嵌入 discord.py
discord.Embed not being treated as embed discord.py
首先,很抱歉让标题人员感到困惑,但我不知道如何更准确地称呼它。
所以这是我的问题:我有用于从上一条消息中获取 discord.Embed
object 的代码:
创建嵌入:
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)
正在嵌入 object:
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
object 不是 discord.Embed
object(我猜?)
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
object
我认为你需要写 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)
如果您仍然有任何错误,请提供更多代码,因为这是我可以从您提供的示例中找到的所有代码。
我假设 ctx.sent.id
指的是消息 ID,您应该使用 ctx.message.id
首先,很抱歉让标题人员感到困惑,但我不知道如何更准确地称呼它。
所以这是我的问题:我有用于从上一条消息中获取 discord.Embed
object 的代码:
创建嵌入:
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)
正在嵌入 object:
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
object 不是 discord.Embed
object(我猜?)
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
object
我认为你需要写 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)
如果您仍然有任何错误,请提供更多代码,因为这是我可以从您提供的示例中找到的所有代码。
我假设 ctx.sent.id
指的是消息 ID,您应该使用 ctx.message.id