python-discord-webhook icon indicating copy to clipboard operation
python-discord-webhook copied to clipboard

NameError: name 'DiscordEmbed' is not defined

Open ambr0sial opened this issue 3 years ago • 4 comments

line: embed = DiscordEmbed(title=(embedtitle), description=(embeddesc), color=(embedcolor))

ambr0sial avatar Apr 23 '22 13:04 ambr0sial

Hey, could you share your imports?

Make sure you import DiscordEmbed from discord_webhook:

from discord_webhook import DiscordEmbed

embed = DiscordEmbed(title=(embedtitle), description=(embeddesc), color=(embedcolor))

vremes avatar Apr 23 '22 18:04 vremes

Hi! Here's my imports:

import json
import requests
import discord_webhook
import time
from pystyle import *

I'll try only importing "DiscordEmbed".

ambr0sial avatar Apr 23 '22 18:04 ambr0sial

So I tried "from discord_webhook import DiscordEmbed" and it says that "webhook" is not defined (from the "webhook.execute()" line). So I tried this:

from discord_webhook import webhook, DiscordEmbed

And now it says:

File "C:\Users\CColdFox\Desktop\My Projects\Python\Novus\main.py", line 145, in main
    webhook.add_embed(embed)
AttributeError: module 'discord_webhook.webhook' has no attribute 'add_embed'

ambr0sial avatar Apr 23 '22 19:04 ambr0sial

Yeah, you have to import DiscordWebhook and DiscordEmbed from discord_webhook.

Then you create instances of DiscordWebhook and DiscordEmbed.

Your code should look something like this:

from discord_webhook import DiscordWebhook, DiscordEmbed

webhook = DiscordWebhook(url='webhook-url-here')

embed = DiscordEmbed(title='My title', description='My description', color='03b2f8')

webhook.add_embed(embed)

response = webhook.execute()

You should refer to Examples section for all kinds of examples.

vremes avatar Apr 23 '22 19:04 vremes