Welcome back, developers.
Greetings to all Steem enthusiasts! We established the necessary environment for developing a Python-based Discord bot during our first lecture. In our second lecture we create a discord bot token, configure the bot and generate the invite link. We use the invite link and added the bot to our server.
Today we are going to activate this bot. We will make our initial Python file and set up the Discord library and bring the Bot online. Let's get started.
- Create a folder community-bot and open it in the PyCharm.
- Create a file main with an extension py (main.py)
- Open the terminal of PyCharm as shown here shortcut Windows (Alt + F12)
- Now, we have to install the Python library. Enter
pip install discord
in PyCharm terminal and hit enter. Ensure that you have a reliable internet connection.
- We have to import Discord and set up the intents, as well as create the client instance. For further information, please visit the link provided: https://discordpy.readthedocs.io/en/stable/quickstart.html
import discord
# configure discord intents
intents = discord.Intents.default()
intents.message_content = True
# creating client instance
client = discord.Client(intents=intents)
- Use the client instance we previously created to generate on_ready and on_message events.
import discord
# configure discord intents
intents = discord.Intents.default()
intents.message_content = True
# creating client instance
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'{client.user} is online')
@client.event
async def on_message(message):
print(message)
client.run('BOT_TOKEN_HERE')
- Now run the project. Our bot will display its online status on the discord server. Use the shortcut for Windows, which is Shift + F10.
- Let's verify if it is currently connected to the discord server.
Yay! Our Community-Bot is now successfully running on a local server. In the next lecture, we will be creating our very first command. Take care and thank you.
Github
Steem Discord Bot Series
Lecture #1: Develop a Discord bot for your Steem Community
Lecture #2: How to Add a Bot to Your Discord Server
SteemPro Official
Download SteemPro Mobile
https://play.google.com/store/apps/details?id=com.steempro.mobileVisit here.
https://www.steempro.comSteemPro Discord
Official Discord Server
Cc: @blacks
Cc: @rme
Cc: @hungry-griffin
Cc: @steemchiller
Cc: @steemcurator01
Cc: @pennsif
Cc: @future.witness
Cc: @stephenkendal
Cc: @justyy
Best Regards @faisalamin
Upvoted! Thank you for supporting witness @jswit.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit