cordslite ๐Ÿบ

A minimal Discord bot library. Like a Coors Lite for Discord โ€” light, refreshing, gets the job done.

Usage

Installation

Install latest from the GitHub repository:

$ pip install git+https://github.com/AnswerDotAI/cordslite.git

or from pypi

$ pip install cordslite

How to use

Setup

Getting a Bot Token:

  1. Go to the Discord Developer Portal
  2. Create an application, then go to โ€œBotโ€ and create a bot
  3. Copy the token and set it as an environment variable:
export DISCORD_BOT_TOKEN='your_token_here'
  1. Under โ€œOAuth2 โ†’ URL Generatorโ€, select bot scope, choose permissions, and use the generated URL to invite the bot to your server

Initialize the client:

from cordslite import *

dc = DiscordClient()

Guilds and Channels

Fetch a guild (server) and explore its channels:

gid = '1327046393453613076'
gld = await dc.get_guild('your_guild_id')
gld
Guild(id=1327046393453613076, name="natedog's server")
chs = await gld.channels(); chs
ID Name Type
1327046393453613077 Text Channels 4
1327046393453613078 Voice Channels 4
1327046393453613079 general 0
1327046393453613080 General 2
1327954661960978512 private 0

Messages

Fetch recent messages from a channel and send one:

ch = chs[2]
msgs = await ch.messages(5); msgs
ID Author Content Date
1469779647867781141 nate.dawgg !err error! 2026-02-07
1469788591751303282 Search Agent Hi, from Solveit! 2026-02-07
1469788597153698007 Search Agent Testing the Gateway! ๐ŸŽ‰ 2026-02-07
1469788597690306633 Search Agent Test our event listener! Otters are awesome ๐Ÿฆฆ 2026-02-07
1469793925655953490 Search Agent Hello from cordslite! ๐Ÿบ 2026-02-07
msg = await ch.send('Hello from cordslite! ๐Ÿบ'); msg
Message(id=1469794127855222875, author='Search Agent', content='Hello from cordslite! ๐Ÿบ')

Gateway (Real-time Events)

The Gateway provides real-time events via WebSocket. Connect, then register handlers for events like MESSAGE_CREATE:

intents = (1 << 0) | (1 << 9) | (1 << 15)  # GUILDS | GUILD_MESSAGES | MESSAGE_CONTENT
gc = GatewayClient(intents, dc)
await gc.start()
Connected! Session: 8bb0098c37e6243270d0c62e90f34097, heartbeat: 41250ms
Gateway started!
Search Agent: Watch this ma!
async def on_msg(msg): print(f"{msg.author['username']}: {msg.content}")

gc.on('MESSAGE_CREATE', on_msg)
msg = await ch.send('Watch this ma!'); msg
Message(id=1469794227717275752, author='Search Agent', content='Watch this ma!')
await gc.stop()
Gateway stopped!

Bot

Bot ties REST and Gateway together with a decorator-based command router. The function name becomes the command name, prefixed with ! in Discord:

bot = Bot(intents)
await bot.start()
Connected! Session: ed2a8f494e50101e6985b6792d20f082, heartbeat: 41250ms
Gateway started!
@bot.cmd
async def echo(msg, args): await (await msg.get_channel()).send(f'You said: {args}')

bot
Bot(cmds=['echo'])
@bot.on_error
async def handle_err(msg, e): print(f'Error: {e}')

await bot.stop()
Gateway stopped!

Errors in command handlers are caught and stored in bot.errors for debugging. You can also register a real-time error handler:

Voice

Join a voice channel, record audio, and leave:

bot = Bot(intents)
await bot.start()

vch = (await gld.channels())[3]  # your voice channel
vc = await bot.join_voice(vch)
vc.start_recording(path='/tmp/recording.mp3')
Connected! Session: c20f63cc3fcb71e75d90d72e04d961c2, heartbeat: 41250ms
Gateway started!
Voice ready!
'/tmp/recording.mp3'
import time
time.sleep(5)
pth = vc.stop_recording()
await bot.leave_voice()
await bot.stop()
Gateway stopped!
from IPython.display import Audio
Audio(pth[0])