Discord.py-AttributeError:模块“ discord”没有属性“嵌入”

时间:2018-09-16 16:18:59

标签: python heroku discord.py

尝试使用Discord时出现错误。嵌入到Discord Bot中。

  

2018-09-16T15:46:20.254940 + 00:00 app [worker.1]:忽略命令dave中的异常   2018-09-16T15:46:20.256521 + 00:00 app [worker.1]:追溯(最近一次拨打电话):   2018-09-16T15:46:20.265538 + 00:00 app [worker.1]:文件“ /app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py” ,第50行,已包裹   2018-09-16T15:46:20.265541 + 00:00 app [worker.1]:ret = coro的收益(* args,** kwargs)   2018-09-16T15:46:20.265590 + 00:00 app [worker.1]:文件“ bot.py”,行83,在dave中   2018-09-16T15:46:20.265592 + 00:00 app [worker.1]:embed = discord.Embed(title = data ['output'],colour = discord.Colour(0x99cc))   2018-09-16T15:46:20.265669 + 00:00 app [worker.1]:AttributeError:模块'discord'没有属性'Embed'   2018-09-16T15:46:20.265720 + 00:00 app [worker.1]:   2018-09-16T15:46:20.265722 + 00:00 app [worker.1]:上面的异常是以下异常的直接原因:   2018-09-16T15:46:20.265723 + 00:00 app [worker.1]:   2018-09-16T15:46:20.265765 + 00:00 app [worker.1]:追溯(最近一次拨打电话):   2018-09-16T15:46:20.265840 + 00:00 app [worker.1]:文件“ /app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/bot.py”在process_commands中的822行   2018-09-16T15:46:20.265842 + 00:00 app [worker.1]:从command.invoke(ctx)产生   2018-09-16T15:46:20.265885 + 00:00 app [worker.1]:文件“ /app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py”在调用中,行367   2018-09-16T15:46:20.265887 + 00:00 app [worker.1]:注入的产量(* ctx.args,** ctx.kwargs)   2018-09-16T15:46:20.265928 + 00:00 app [worker.1]:文件“ /app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py” ,第52行,已包裹   2018-09-16T15:46:20.265930 + 00:00 app [worker.1]:从e引发CommandInvokeError(e)   2018-09-16T15:46:20.265995 + 00:00 app [worker.1]:discord.ext.commands.errors.CommandInvokeError:命令引发了异常:AttributeError:模块'discord'没有属性'Embed'

是控制台中的完整输出。

我的相关代码如下:

from discord.ext.commands import Bot
from discord.ext import commands
import discord
import json
import random
import requests

client = Bot(description="My Bot", command_prefix="~")

@client.command(pass_context=True)
async def dave(ctx, *, query = ""):
    ''' Talks to Dave '''

    if query == "":
        await client.say("Sample usage: ```~dave Hello```")
    else:
        r = requests.get('https://example.com/dave/api.php?discord=' + str(ctx.message.author.id) + '&query=' + str(query))
        data = r.json()
        data = json.dumps(data)
        data = json.loads(data)

        if data['status'] == "unknown":
            unsure = ["I don't know how to do that yet.", "Hmm... I am unsure.", "Sorry, you appear to have confused me.", "I don't know how to help you with that."]
            await client.say(random.choice(unsure))
            return

        embed = discord.Embed(title=data['output'], colour=discord.Colour(0x99cc))

        if data['discordAction'] != None:
            embed.set_image(url=data['discordAction'])

        embed.set_author(name="Dave", url="https://example.com/dave/", icon_url="https://example.com/Storage_new/2018/small/dave-small.png")
        embed.set_footer(text="Powered by Dave", icon_url="https://example.com/drive/uploads/1/bv3gfc333mceuaqw8jlpyrnrfiqi7r/f73h4m12qdxl45n.png")
        await client.say(embed=embed)

client.run('intentionally removed')

该文件也称为bot.py。该代码已更改为示例而不是我的实际域,依此类推。在我介绍discord.Embed部分之前,所有代码都有效。

2 个答案:

答案 0 :(得分:0)

  

所有代码都起作用,直到我引入了discord.Embed部分。

我想我知道为什么...它可能已经过时了。

在这里,尝试使用以下命令: pip install --upgrade discord.py

答案 1 :(得分:0)

我认为问题在于您需要导入嵌入,这是我为修复它所做的:from discord import Embed