首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >discord.Embed不被视为嵌入discord.py

discord.Embed不被视为嵌入discord.py
EN

Stack Overflow用户
提问于 2020-11-24 15:34:22
回答 2查看 293关注 0票数 0

首先,很抱歉混淆了标题,但我不知道如何更准确地称呼它。

因此,我的问题是:我有用于从先前消息中获取discord.Embed对象的代码:

嵌入式的创建:

代码语言:javascript
复制
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)

获取嵌入对象:

代码语言:javascript
复制
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对象(我猜?)

代码语言:javascript
复制
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对象一样对待它

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-11-24 15:43:32

我认为您需要编写sent.id而不是ctx.sent.id

代码语言:javascript
复制
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)

如果您仍然有任何错误,请提供更多的代码,因为这是所有我可以找到的样本,您提供。

票数 2
EN

Stack Overflow用户

发布于 2020-11-24 16:03:45

我假设ctx.sent.id是指消息id,您应该使用ctx.message.id

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64989717

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档