Getting Started
After you installed this package, the next step is to import the package into your code and start using the functions.
from botcity.plugins.discord import BotDiscordPlugin
As a demonstration of the library, let's build a simple example together that will do something cool .
Setting up
To use this pugin you have to create a webhook. Look this article to learn how to create a new webhook.
Send message
from botcity.plugins.discord import BotDiscordPlugin
url = 'https://discord.com/api/webhooks/95811659/Y6uu4DOUH'
ds = BotDiscordPlugin(urls=url, username="Bot Discord Name")
res = ds.send_message(content='Hello!')
print(res)
Result
Send embedded content
from botcity.plugins.discord import BotDiscordPlugin, EmbeddedMessage, Author, Footer, Field, Color
msg = EmbeddedMessage(title='Title Embedded', description='Long Description.', color=Color.ORANGE)
msg.author = Author(
name='Botcity',
url='https://github.com/botcity-dev',
icon_url='https://avatars.githubusercontent.com/u/72993825?s=200&v=4'
)
msg.footer = Footer(
text='Footer text example',
icon_url='https://cdn3.iconfinder.com/data/icons/logos-and-brands-adobe/512/267_Python-512.png' # python icon
)
msg.fields = [Field(name='Field 1', value='Value 1'), Field(name='Field 2', value='Value 2')]
msg.thumbnail = 'https://pbs.twimg.com/profile_images/1374747222353575944/7kS6IhZb_400x400.jpg' # botcity icon
msg.image = 'https://cdn-icons-png.flaticon.com/512/2111/2111370.png' # discord logo
url = 'https://discord.com/api/webhooks/95811659/Y6uu4DOUH'
ds = BotDiscordPlugin(urls=url, username="Bot Discord Name")
res = ds.send_embedded_message(msg)
Result
Edit message
from botcity.plugins.discord import BotDiscordPlugin
url = 'https://discord.com/api/webhooks/95811659/Y6uu4DOUH'
ds = BotDiscordPlugin(urls=url, username="Bot Discord Name")
first_message_response = ds.send_message(content='Hello!')
updated_message_response = ds.edit_message(first_message_response, 'New content.')
print(updated_message_response)
Result
File upload
from botcity.plugins.discord import BotDiscordPlugin
url = 'https://discord.com/api/webhooks/95811659/Y6uu4DOUH'
ds = BotDiscordPlugin(urls=url, username="Bot Discord Name")
res = ds.send_file(files=['<path-to-image>'])
print(res)
Result
Delete message/file
Info
The delete_message()
method takes the response from an action.
import time
from botcity.plugins.discord import BotDiscordPlugin
url = 'https://discord.com/api/webhooks/95811659/Y6uu4DOUH'
ds = BotDiscordPlugin(urls=url, username="Bot Discord Name")
res = ds.send_message(content='...')
# res = ds.send_message(...)
# res = ds.edit_message(...)
# res = ds.send_embedded_message(...)
time.sleep(5)
ds.delete_message(res)
Next Steps
Check our examples and experiment with the API. Let us know where it can be improved.
Have fun automating!