Make a Discord Bot with Python - Part 2

If you don't already have a Discord server and a bot, you might want to check out Making a Discord Bot in Python - Part 1 which covers how to create a server, create a Discord app, create a bot user, authorize the bot for your server, and test it all with a Python script. This assumes you already have a bot account ready to go.

If you want to check out some bots that are already made, check out two DevDungeon projects: Chatty Cathy AI chat bot and Help Desk Bot a fun utility bot, both written in Python.

Bot Code

import random
import asyncio
import requests
from discord import Game
from discord.ext.commands import Bot

BOT_PREFIX = ("?", "!")

client = Bot(command_prefix=BOT_PREFIX)

                description="Answers a yes/no question.",
                brief="Answers from the beyond.",
                aliases=['eight_ball', 'eightball', '8-ball'],
async def eight_ball(context):
    possible_responses = [
        'That is a resounding no',
        'It is not looking likely',
        'Too hard to tell',
        'It is quite possible',
    await client.say(random.choice(possible_responses) + ", " +

async def square(number):
    squared_value = int(number) * int(number)
    await client.say(str(number) + " squared is " + str(squared_value))

async def on_ready():
    await client.change_presence(game=Game(name="with humans"))
    print("Logged in as " +

async def bitcoin():
    url = ''
    response = requests.get(url)
    value = response.json()['bpi']['USD']['rate']
    await client.say("Bitcoin price is: $" + value)

async def list_servers():
    await client.wait_until_ready()
    while not client.is_closed:
        print("Current servers:")
        for server in client.servers:
        await asyncio.sleep(600)