Skip to content

Commit d617ddd

Browse files
committed
add examples as python files
1 parent d2996db commit d617ddd

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed

examples/attachment_in_embeds.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from discord_webhook import DiscordWebhook, DiscordEmbed
2+
3+
webhook = DiscordWebhook(url='your webhook url')
4+
5+
with open("path/to/image.jpg", "rb") as f:
6+
webhook.add_file(file=f.read(), filename='example.jpg')
7+
8+
embed = DiscordEmbed(title='Embed Title', description='Your Embed Description', color=242424)
9+
embed.set_thumbnail(url='attachment://example.jpg')
10+
11+
webhook.add_embed(embed)
12+
webhook.execute()

examples/basic_webhook.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from discord_webhook import DiscordWebhook
2+
3+
webhook = DiscordWebhook(url='your webhook url', content='Webhook Message')
4+
webhook.execute()

examples/embedded_content.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from discord_webhook import DiscordWebhook, DiscordEmbed
2+
3+
webhook = DiscordWebhook(url='your webhook url')
4+
5+
# create embed object for webhook
6+
embed = DiscordEmbed(title='Your Title', description='Lorem ipsum dolor sit', color=242424)
7+
8+
# set author
9+
embed.set_author(name='Author Name', url='author url', icon_url='author icon url')
10+
11+
# set image
12+
embed.set_image(url='your image url')
13+
14+
# set thumbnail
15+
embed.set_thumbnail(url='your thumbnail url')
16+
17+
# set footer
18+
embed.set_footer(text='Embed Footer Text')
19+
20+
# set timestamp (default is now)
21+
embed.set_timestamp()
22+
23+
# add fields to embed
24+
embed.add_embed_field(name='Field 1', value='Lorem ipsum')
25+
embed.add_embed_field(name='Field 2', value='dolor sit')
26+
27+
# add embed object to webhook
28+
webhook.add_embed(embed)
29+
30+
webhook.execute()

examples/send_files.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from discord_webhook import DiscordWebhook, DiscordEmbed
2+
3+
webhook = DiscordWebhook(url='your webhook url', username="Webhook with files")
4+
5+
# send two images
6+
with open("path/to/first/image.jpg", "rb") as f:
7+
webhook.add_file(file=f.read(), filename='example.jpg')
8+
with open("path/to/second/image.jpg", "rb") as f:
9+
webhook.add_file(file=f.read(), filename='example2.jpg')
10+
11+
webhook.execute()

examples/use_proxy.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from discord_webhook import DiscordWebhook
2+
3+
proxies = {
4+
'http': 'http://10.10.1.10:3128',
5+
'https': 'http://10.10.1.10:1080',
6+
}
7+
webhook = DiscordWebhook(url='your webhook url', content='Webhook Message', proxies=proxies)
8+
webhook.execute()

0 commit comments

Comments
 (0)