Archived in favour of Rewrite using PyCord
A discord bot written by Mahasvan in python using the library Discord.py. Don't use my code without giving credit. You are free to host it and fork it yourself but don't claim any of this code as yours.
If all you want is a stable instance of the bot, I'd recommend using my instance - Link
- Download the repo's files
- Get the Discord Bot Application's token (while setting the appropriate OAuth permissions)
- Fill in the Reddit App details
- Fill in Spotify Application Details
- Get the API key from RSA
- Get the currency API key from ExchangeRatesAPI
- Get weather API Key from OpenWeatherMap
- Make an Imgflip account
- Fill in details in
config.json
andreddit_details.json
- Actually run the bot
Download the repo as zip or do the following below in a terminal window (You need git for this):
git clone https://github.com/Code-Cecilia/BotMan.py
cd
into the project's directory and run this command
python3 -m pip install -r requirements.txt
Note that you also need git
for the above command to work properly.
Get to the Discord Developer Portal and make a new application.
You also need to enable Privileged gateway intents in the Bot
section of your application's page
This screenshot above is outdated, enable all Privileged Intents for the bot to work properly.
Now that you have copied your token, paste it in config.json
in its corresponding entry.
RSA (Random Stuff API) is what we use for BotChat in this bot. For this to work, we need to get an API Key.
You can get one Here by signing up with discord. It adds you to a server, and sends you a PM with the API key.
When you get it, set the value of rsa_api_key
to the API key you recieved.
ExchangeRatesAPI is what this bot uses for working with currency. You can get an API key Here.
When you get the API key, copy and paste it into the currency_api_key
entry in the config.json
file.
OpenWeatherMap has a free plan with ample amount of calls per month. You can get an API Key here.
After getting the API key, paste it in the weather_api_key
entry in config.json
Go to imgflip.com and make an account. Take note of your username and password and fill it in config.json
.
This information is used for the memegen
command in the Memes Cog.
A properly set-up config.json looks something like this
{
"prefix": "bm-",
"token": "ODQ4NTI5xxxxx._cvTBeEHbk1z6iTtCHY92TFN5DU",
"owner_id": "775176626773950474",
"rsa_api_key": "XXXXXXXXXX",
"currency_api_key": "XXXXXXXXXX",
"weather_api_key": "abc1234xyz",
"imgflip_username": "username",
"imgflip_password": "password"
}
owner_id
is the ID of the owner (ie. you.). This is used for various owner-only commands
- reload
- reboot
- shutdown
These are some of the owner-only commands available.
Note: If you're going to host the bot in Repl.it, check the bottom of this page for extended information.
You're gonna need to setup an application for proper functioning of the commands that use Reddit (nocontext, meme).
Go to Reddit, and make a new account (or use the one you have.)
The first step you need to do is turn on dark mode, because that's what cool people do 😎
Now go to the Reddit Applications page
If you already have an app, you'd see something like this
You'd probably feel disappointed, cause the dark mode doesn't reflect in this page. (I know. I feel disappointed too.)
If you don't have an app already, you'd see something like "Create an app"
What you need to do now, is to enter these details
- Name - Input any name for your application
- Choose the
script
checkbox - set
about url
andredirect url
ashttps://localhost:8080
(It's what I do. If you know what you're doing, feel free to mess around.) - Click on
Create app
Now, you'd see an entry for your application above the portion of the screen where you entered the details. (weird, I know.)
You can get the Client ID and Client Secret from these entries
Fill in the details for your reddit application in reddit_details.json
.
client_id
is the Client ID we got from the application (the one under the application name in the above screenshot)client_secret
is the Client Secret we got from the entry calledsecret
username
is the username of the Reddit account you used to make the applicationpassword
is the password of the Reddit account you used to make the application
A properly set-up reddit_details.json
looks something like this.
{
"client_id" : "E3RXXXXXXXjlKzOg",
"client_secret": "nEdXXXXXXXXXS_9tBYyo1Q",
"username": "myRedditUsername",
"password": "myPassword"
}
This bot has a Spotify category that can get information on artists and categories (more coming soon!).
To make this work, we need an application, You can make one here.
After signing on, your page should look something like this.
Click on "Create An App"
Copy the Client ID and Client Secret and paste them in their respective fields in spotify_details.json
.
A fully configured spotify_details.json
looks something like this
{
"client_id": "b0d95fb2d92241d690c109314c09dd8d",
"client_secret": "c7b628b7b52a47f29bb82adfa1049a11"
}
It is recommended to change the variable replit
to False
in main.py
. I keep it on as True, but you might want to change it to False.
And that should be it.
You can run main.py
to run the bot. I'm working on a startup file, so bear with me till I finish it.
If you're going to host your bot on repl.it, these steps can be followed for features like 24/7 functioning without paying.
- Change the
replit
variable inmain.py
fromFalse
toTrue
.
# previous lines
# status_link = details_data['status_link']
# owner_id = int(details_data['owner_id'])
replit = True # change this to False or True depending on your need
# intents = discord.Intents.default()
# continuing lines
This enables 24/7 functioning of your bot without the premium plan. (pretty cool, huh?)
-
Delete
requirements.txt
from the Repl's project files, or rename it to something else for the first startup. It kind-of hindered the first setup for me, and I don't know why. You can add it later when the first boot is done, and the dependencies are installed automatically and the lock file is in place. -
If you follow the above point, you'll probably find a few Cogs fail to load. If that is the case, install the dependencies one by one via the shell. Requests, AsyncPraw, and Prsaw need to be installed separately, as of the time I am writing this.
-
If Replit errors out while installing the dependencies from the lock file, remove modules that conflict.
Continuation for 24/7 Replit functioning. You need to follow this step, or it won't work.
-
When you run your repl, you'll see a web view pop up. (top-right in most cases). You need to copy the URL of this page.
-
Make an account in UptimeRobot
-
add a new monitor with these credentials
Monitor type: HTTP(S) Friendly Name : Whatever you want URL : The URL we copied earlier Monitoring Interval : I'd recommend setting it to 30 minutes, but you can go as low as 5 minutes for this.
You don't need to change any other settings. Click on
Create Monitor
to create the monitor.
Good question.
Free Repls shut down (More like sleep) after 60 minutes of inactivity. So we ping the bot every [x] minutes to prevent the bot from shutting down.
That's pretty much it. You can select an alert email while making the UptimeRobot Monitor to notify you if the bot goes offline, but I don't really know how far it works, since I haven't tried it yet.
-
Open up Command Prompt, Terminal, or what you have in your OS
-
(Very important)
cd
into the directory of the project. (if this is not done, it might break everything that uses the OS module, and maybe a few others)
cd [path to project folder]
- run this command
python3 main.py
- Enjoy.
CorpNewt for CorpBot.py, from which I got the ideas of quite a few commands from.
YuiiiPTChan for helping me with commands, and agreeing to work on the bot together.
Discord.py for obvious reasons
And a LOT of friends who helped make this bot what it is today. Thanks, guys!