NameError: name 'DiscordEmbed' is not defined
line: embed = DiscordEmbed(title=(embedtitle), description=(embeddesc), color=(embedcolor))
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))
Hi! Here's my imports:
import json
import requests
import discord_webhook
import time
from pystyle import *
I'll try only importing "DiscordEmbed".
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'
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.