Code Monkey home page Code Monkey logo

Comments (5)

lovvskillz avatar lovvskillz commented on May 21, 2024

@morriscotty well, this behavior is strange. I tried to reproduce the issue but I did not succeed. Could you provide me the full example?
Or your function may have been called several times?

from python-discord-webhook.

morriscotty avatar morriscotty commented on May 21, 2024

It is only happening sometimes for myself so may be hard to reproduce and does make me think it could be some sort of latency issue either on Discord's end or Heroku's end where the script is hosted. The function is definitely only being called once, I also have a slack and twitter script that is called at the same time without these issues.

Below is the script being used with some data retracted and dummy data in its place:

...
from discord_webhook.webhook import DiscordWebhook, DiscordEmbed
...

#Defined globally
webhook1 = DiscordWebhook(url='webhook_url',username="Usernmame")
webhook2 = DiscordWebhook(url='webhook_url',username="Usernmame")
webhook3 = DiscordWebhook(url='webhook_url',username="Usernmame")
webhook4 = DiscordWebhook(url='webhook_url',username="Usernmame")
webhook5 = DiscordWebhook(url='webhook_url',username="Usernmame")

...

def post_discord():
    embed = DiscordEmbed(title='Title', description='Description')
    embed.set_footer(text='My Footer')
    embed.set_timestamp()
	embed.add_embed_field(name='My Field', value='Field Value')
    embed.set_thumbnail(url='thumbnail_url')

    webhook1.add_embed(embed)
    webhook1.execute()

    webhook2.add_embed(embed)
    webhook2.execute()

    webhook3.add_embed(embed)
    webhook3.execute()

    webhook4.add_embed(embed)
    webhook4.execute()

    webhook5.add_embed(embed)
    webhook5.execute()

	
...

def live():
    if request.method == 'POST':
        ...
        post_discord()
        ...
    else:
        ...

from python-discord-webhook.

lovvskillz avatar lovvskillz commented on May 21, 2024

I tried it but I don't get the same message multiple times.
If I execute the function in a loop, I received the same embed message multiple times.
But this behavior was expected because another embed was added to the webhook.

from discord_webhook.webhook import DiscordWebhook, DiscordEmbed

embed = DiscordEmbed(title='Title', color=242424)
webhook1 = DiscordWebhook(url="URL")
webhook2 = DiscordWebhook(url="URL")
webhook3 = DiscordWebhook(url="URL")
webhook4 = DiscordWebhook(url="URL")
webhook5 = DiscordWebhook(url="URL")


def post():
    webhook1.add_embed(embed)
    webhook1.execute()
    webhook2.add_embed(embed)
    webhook2.execute()
    webhook3.add_embed(embed)
    webhook3.execute()
    webhook4.add_embed(embed)
    webhook4.execute()
    webhook5.add_embed(embed)
    webhook5.execute()


i = 0
while i < 3:
    embed.set_description(i)
    i += 1
    post()

grafik

You could remove the embed from the webhook after it was executed. Maybe this will fix it.

from discord_webhook.webhook import DiscordWebhook, DiscordEmbed

embed = DiscordEmbed(title='Title', color=242424)
webhook1 = DiscordWebhook(url="URL")
webhook2 = DiscordWebhook(url="URL")
webhook3 = DiscordWebhook(url="URL")
webhook4 = DiscordWebhook(url="URL")
webhook5 = DiscordWebhook(url="URL")


def post():
    webhook1.add_embed(embed)
    webhook1.execute()
    webhook1.remove_embed(0) # remove from index 0

    webhook2.add_embed(embed)
    webhook2.execute()
    webhook2.remove_embed(0)

    webhook3.add_embed(embed)
    webhook3.execute()
    webhook3.remove_embed(0)

    webhook4.add_embed(embed)
    webhook4.execute()
    webhook4.remove_embed(0)

    webhook5.add_embed(embed)
    webhook5.execute()
    webhook5.remove_embed(0)


i = 0
while i < 3:
    embed.set_description(i)
    i += 1
    post()

grafik

from python-discord-webhook.

morriscotty avatar morriscotty commented on May 21, 2024

Good idea I'll give that a try. I think it's safe to close the issue off as I don't think it's an issue with the plugin itself. Thanks for the help.

from python-discord-webhook.

vremes avatar vremes commented on May 21, 2024

I also encountered this issue, but i wrote subclass that overrides execute method and makes sure there are no embeds left over in self.embeds after execute is called.

Example:

from discord_webhook import DiscordWebhook

class CustomDiscordWebhook(DiscordWebhook):
    def execute(self):
        e = super().execute()

        embeds = self.get_embeds()
        for i, embed in enumerate(embeds):
            self.remove_embed(i)

        return e

discord_webhook = CustomDiscordWebHook(url=[...])

I've taken a closer look at the code in this repository and calling DiscordWebhook.execute method calls DiscordWebhook.json which should set self.embeds to empty list, but i guess there is some kind of condition where this fails.

from python-discord-webhook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.