Bring the Steem Discord Bot Online | Steem Discord Bot Python #3

in hive-151113 •  2 years ago 

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.

lecture3.png

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)

image.png

  • 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.

image.png

import discord

# configure discord intents
intents = discord.Intents.default()
intents.message_content = True

# creating client instance
client = discord.Client(intents=intents)

image.png

  • 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')

image.png

  • Now run the project. Our bot will display its online status on the discord server. Use the shortcut for Windows, which is Shift + F10.

image.png

image.png

  • Let's verify if it is currently connected to the discord server.

image.png

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

SteemPro Official

Cc: @blacks
Cc: @rme
Cc: @hungry-griffin
Cc: @steemchiller
Cc: @steemcurator01
Cc: @pennsif
Cc: @future.witness
Cc: @stephenkendal
Cc: @justyy


Best Regards @faisalamin

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Upvoted! Thank you for supporting witness @jswit.