Comments (5)
@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.
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.
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()
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()
from python-discord-webhook.
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.
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)
- raise InvalidSchema(f"No connection adapters were found for {url!r}") HOT 1
- [1/1] Webhook status code 400: {"embeds": ["0"]} whenever I'm trying to add a longer url to the webhook's embed.
- Add `thread_id` support
- TypeError: Object of type Embed is not JSON serializable HOT 2
- Multiple webhook URLs not working in v1.0.0 HOT 2
- Can't remove files when using webhook.edit() HOT 2
- Timezone for set_timestamp() HOT 1
- Add donation link or GitHub Sponsors
- Add better support for sending several images HOT 2
- Add a parameter to delete a message by id, webhook.delete() method HOT 1
- Image not loading in Discord
- JSON Decode Error when executing webhook HOT 3
- Hits rate limit and got me blocked temporarily
- Using timeout param > 1 on Webhook causes 400 HOT 1
- Webhook status code 400 HOT 2
- Object of type DiscordComponentButton is not JSON serializable HOT 1
- Feature DiscordEmbed.from_dict(embed_json)
- Allowed mentions now expects a dictionary and not a list HOT 1
- feature request: search for threads
- Avatar Url not showing in create_batch call
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-discord-webhook.