~/projects/gexbot
A discord bot that provides a random image from the designated folder, along with a random quote from a text file.
Gex the Gecko is a platformer game series with releases spanning from 1994-1999. I was looking for a python-based project and a discord bot seemed like the perfect idea. The eventual goal was a bot that would respond with a random quote and image from an easy to modify filesystem. I parsed a website containing all known in-game quotes into a text file and proceeded to crowd-source any related images.
Note: This project has been deprecated due to a change in Discord policies regarding bot interactions, see this announcement for more information. This project for reference-only.
highlights
- Created in Python 3 using discord.py version 1.3.x.
- Shared source repo for text/image files. Allowed any discord member to add/modify content.
- Hosted locally on a Raspberry Pi 4.
- Responded to the
!gex
command in chat.
example code
import random
from discord.ext.commands import Bot
from discord import File
import os
import math
discord_token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
bot = Bot(command_prefix='!')
@bot.event
async def on_ready():
print("Login as")
print(bot.user.name)
print("-------")
@bot.command(name='gex')
async def random_gex(ctx):
if os.path.exists('textlist.txt'):
lines = open('textlist.txt', encoding='utf-8').read().splitlines()
text = random.choice(lines)
image = os.listdir('./images/')
imgString = random.choice(image)
path = "./images/" + imgString
await ctx.send(file=File(path))
await ctx.send(text)
bot.run(discord_token)
images