Playing around with writing a Discord bot in Ruby.
Discord API Library: https://github.com/shardlab/discordrb
Instructions on how to run locally via dev container, or as a docker compose service.
Install Docker Desktop to be able to run the compose file locally, or install Docker using your existing methods.
https://docs.docker.com/desktop/
To run, you'll either need to install the nvidia container toolkit, or disable the GPU reservation in the docker-compose.yml.
https://hub.docker.com/r/ollama/ollama
- Configure the repository
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey \
| sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list \
| sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' \
| sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt-get update
- Install the NVIDIA Container Toolkit packages
sudo apt-get install -y nvidia-container-toolkit
- Configure Docker to use Nvidia driver
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker
From the Discord Developer Portal: https://discord.com/developers/applications
Create a new application for your bot. You'll want to save the token to your password manager, as it will be needed to test and run the bot.
Also, you'll want to enable all of the Privileged Gateway Intents, otherwise you will run into errors on startup due to permission mismatch.
cp .env.sample .env
Edit the .env
file, and add the bot token from above.
If you have VS Code, and are familiar with dev containers, you can test the bot locally as you would normally for any other application.
If you need to stop the service and restart it, the entrypoint from terminal is:
bundle exec ruby lib/discord_bot.rb
If however, you're looking to use this as a service, you can run it using Docker Compose:
docker compose up -d
Follow the logs by grabbing the docker container id:
docker ps
Then tailing the logs (exit logs with ctrl+c
):
docker logs -f container_id
To bring down the service and update it:
docker compose down
docker compose pull