以 embed.set 开头的所有内容都不起作用
@bot.command()
async def test(ctx):
emb = discord.Embed(
title="Title", description="This is a description", colour=discord.Colour.blue())
# Отсюда не работает
embed.set_footer(text="This is a footer.")
embed.set_image(url="https://cdn.discordapp.com/attachments/520265639680671747/533389224913797122/rtgang.jpeg")
embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/520265639680671747/533389224913797122/rtgang.jpeg")
embed.set_author(name="Author Name",
icon_url="https://cdn.discordapp.com/attachments/520265639680671747/533389224913797122/rtgang.jpeg")
# До сюда
await ctx.send(embed=emb)
命令前的代码:
import discord
from discord.ext import commands
TOKEN = ''
client = discord.Client()
bot = commands.Bot(command_prefix='$')
错误文字:
Ignoring exception in command test:
Traceback (most recent call last):
File "D:\pyprojects\venv\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "D:/pyprojects/Embed bot/DsBotMain.py", line 48, in test
embed.set_footer(text="This is a footer.")
AttributeError: 'Command' object has no attribute 'set_footer'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\pyprojects\venv\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "D:\pyprojects\venv\lib\site-packages\discord\ext\commands\core.py", line 859, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "D:\pyprojects\venv\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Command' object has no attribute 'set_footer'
错误是您创建了一个带有 name的嵌入
emb,然后尝试将图像和其他内容添加到它,而不是添加到一个不存在的 objectembed。在下面的行中,替换
embed为您的对象emb另外,关于一个小问题。
您在代码中声明了 2 个机器人:
和
同时,第二个具有更多功能,因为它可以处理命令。我建议
discord.Client()从代码中删除它并client简单地将所有内容替换为bot. 也会工作