Coders Packet

Hangman Game Discord Bot in Python

By Shubham Menroy

It is a hangman game bot and also a welcome bot which is developed in python using the Discord.py module

Hi, today we will learn how to make a discord game bot and also a welcome bot that welcomes newly added members to the channel in python using the Discord.py module.

So let's begin first we have to create a bot so we have to visit the discord developers page(Click here). Then we have to create a new Application.

After that, you have to give it a name and press on create button after which a new page will be opened like the picture given below.

Now we have to click on Bot in the left side menu and we have to add a bot. Now we have to go to the OAuth2 page by clicking on the OAuth2 from the left side menu and then select bot and give permissions to the bot according to your needs you can see how it will look after all these steps in the given below picture.

After it, we have to copy that link that was given above Bot Permissions after selecting the permissions and paste it in the new tab of the browser then select the server in which you want to add this bot and authorized it and then a window will occur like given below picture.

Then we have to close this tab come again to the previous tab then we have to again open Bot and copy token by clicking on the copy button(Note: don't share this token with anyone).

Now paste this token no in the .env file in the downloaded packet folder and save it like given below picture.

Next, we have to open discord and go to user settings and click on Advanced and switch ON developer mode after it saves changes. Now we have to go to server settings in which we added our Bot and open widget from the menu after which we have to copy the server-id like given below image.

Now past this id in the .env file and save it. Now go to the server again and click right click on the welcome text channel and copy its id just like give below picture.

Now paste this id in env and save that file.

Next, open the command prompt and run the two given below commands.

pip install discord.py
pip install python-dotenv

After performing all the steps you have just run the bot.py file. If the output of the bot.py is [email protected] has connected to discord (Here the Botname and the botid refers to your chatbot name and its id).

And woohoo your chatbot ready now enjoy its features and play hangman with your chatbot.

Commands to use chatbot are:-

Hii or Hello: it will reply hello

!help: it will return a list of commands

!Ping to Ping the bot

!hangman start to start the game

!hangman x to play the game where x is the Alphabetic letter.

 

Thank You for reading this blog.

I hope you like it.

 

Download project

Reviews Report

Submitted by Shubham Menroy (shubham9672)

Download packets of source code on Coders Packet