A discord.py bot template with easy deployment through Github Actions

Overview

discord.py bot template

A discord.py bot template with easy deployment through Github Actions. You can use this template to just run a Python instance, Docker image, or Docker compose with other microservices. This is why it features a mockup API aswell, to showcase the flexibility of it.

Registering a new bot

Go to Discord Developer Applications Portal And create a new application. Then go to Bot -> Add Bot. Give it a name and the required permissions for your use case. Now use Click to Reveal Token to get your token, you will need this in configuration. Do not share this with anyone! If for some reason the token got leaked, you can regenerate a new one. This means you need to this this in the configuration later on aswell, so only do this when necessary.

Configuration

First you'll have to create a .env file. This is a file where all configuration is stored for this bot. If you are going to run this in a simple way locally, use the example.env file and fill in the field with your discord token. And save this with the file name only being: ".env" The script will now use this file to access the token.

Suggested: If you are planning to take the automated deployment approach, you will not need to put this key inside the .env file. Go to the Automated deployment pipeline section to set this up.

Running in docker

I'm going straight to running in docker. First you will have to build the docker image. You can do this by going inside the directory that contains the dockerfile and running the command:

docker build . -t 

To run the bot you can use:

docker run --env-file 
    
    

   

you can add the -d flag to run in detached mode. Even easier is using docker-compose. When working with different microservices this is must!

docker-compose -f 
   
     up --build

   

Use the --build flag if you've made changes. It won't rebuild every layer because it can use the cached one's, this means the whole process just takes a couple of seconds.

Automated deployment pipeline

First you'll have to generate a Personal Access Token. Keep a copy of this, you wont be able to access it once it's generated. You will put this key and the discord token inside the repository secrets under Settings -> Secrets -> Actions and create a new secret with the same key value pair. Now the tokens are accessible by Github Actions, but remain anonymous. Also other people with access to the repo can't see it, including yourself. From now on you're only able to write to these. Also add your user

image

Now set up a self-hosted runner. Ideally this is configured as a service so that it runs permanently and launches on startup. You can add a runner by going to Settings -> Actions -> Runners and add a new one. Follow the instructions for your platform. For this example I did it in my WSL Debian. Make sure docker is installed on this machine when running the action runner.

image

When starting the runner you should see the it appear with the idle status. I recommend this doc to get it up and running as a service. If you want to just quickly run it using the run.sh script, make sure that your user has the right privileges to do this. Check out this post if you encounter an error due to this problem.

image

Now Github Actions will use this machine to deploy the bot.

You might also like...
Mini Tool to lovers of debe from eksisozluk (one of the most famous website -reffered as collaborative dictionary like reddit- in Turkey) for pushing debe (Most Liked Entries of Yesterday) to kindle every day via Github Actions.

debe to kindle Mini Tool to lovers of debe from eksisozluk (one of the most famous website -refered as collaborative dictionary like reddit- in Turkey

POC de uma AWS lambda que executa a consulta de preços de criptomoedas, e é implantada na AWS usando Github actions.
POC de uma AWS lambda que executa a consulta de preços de criptomoedas, e é implantada na AWS usando Github actions.

Cryptocurrency Prices Overview Instalação Repositório Configuração CI/CD Roadmap Testes Overview A ideia deste projeto é aplicar o conteúdo estudado s

GitHub Actions Poll Mode AutoScaler (GAPMAS)

GitHub Actions Poll Mode AutoScaler, or GAPMAS, is a simple tool that helps you run ephemeral GitHub Actions self-hosted runners on your own infrastructure.

Centralized whale instance using github actions, sourcing metadata from bigquery-public-data.
Centralized whale instance using github actions, sourcing metadata from bigquery-public-data.

Whale Demo Instance: Bigquery Public Data This is a fully-functioning demo instance of the whale data catalog, actively scraping data from Bigquery's

A GitHub Actions repo for tracking the dummies sending free money to Alex Jones + co.

A GitHub Actions repo for tracking the dummies sending free money to Alex Jones + co.

Automation that uses Github Actions, Google Drive API, YouTube Data API and youtube-dl together to feed BackJam app with new music

Automation that uses Github Actions, Google Drive API, YouTube Data API and youtube-dl together to feed BackJam app with new music

42-event-notifier - 42 Event notifier using 42API and Github Actions
42-event-notifier - 42 Event notifier using 42API and Github Actions

42 Event Notifier 42서울 Agenda에 새로운 이벤트가 등록되면 알려드립니다! 현재는 Github Issue로 등록되므로 상단

GitHub Actions Docker training

GitHub-Actions-Docker-training Training exercise repository for GitHub Actions using a docker base. This repository should be cloned and used for trai

Receive GitHub webhook events and send to Telegram chats with AIOHTTP through Telegram Bot API

GitHub Webhook to Telegram Receive GitHub webhook events and send to Telegram chats with AIOHTTP through Telegram Bot API What this project do is very

Owner
Thomas Van Iseghem
I create code and stuff...
Thomas Van Iseghem
Implement SAST + DAST through Github actions

Implement SAST + DAST through Github actions The repository is supposed to implement SAST+DAST checks using github actions against a vulnerable python

Syed Umar Arfeen 3 Nov 9, 2022
A github actions + python code to extract URLs to code repositories to put into standard form, starting with github

A github actions + python code to extract URLs to code repositories to put into standard form, starting with github ---- NOTE: JUS

Justin Gosses 2 Nov 15, 2021
Satoshi is a discord bot template in python using discord.py that allow you to track some live crypto prices with your own discord bot.

Satoshi ~ DiscordCryptoBot Satoshi is a simple python discord bot using discord.py that allow you to track your favorites cryptos prices with your own

Théo 2 Sep 15, 2022
Pincer-bot-template - A template for a Discord bot created using the Pincer library

Pincer Discord Bot Template (Python) WARNING: Pincer is still in its alpha/plann

binds 2 Mar 17, 2022
Davide Gallitelli 3 Dec 21, 2021
A clean, easy to scale discord bot template

A clean, easy to scale discord bot template. Develope using nextcord library and can be use with any other discord.py forked library.

めがねこ 3 Mar 3, 2022
Use GitHub Actions to create a serverless service.

ActionServerless - Use GitHub Actions to create a serverless service ActionServerless is an action to do some computing and then generate a string/JSO

null 107 Oct 28, 2022
可基于【腾讯云函数】/【GitHub Actions】/【Docker】的每日签到脚本(支持多账号使用)签到列表: |爱奇艺|全民K歌|腾讯视频|有道云笔记|网易云音乐|一加手机社区官方论坛|百度贴吧|Bilibili|V2EX|咔叽网单|什么值得买|AcFun|天翼云盘|WPS|吾爱破解|芒果TV|联通营业厅|Fa米家|小米运动|百度搜索资源平台|每日天气预报|每日一句|哔咔漫画|和彩云|智友邦|微博|CSDN|王者营地|

每日签到集合 基于【腾讯云函数】/【GitHub Actions】/【Docker】的每日签到脚本 支持多账号使用 特别声明: 本仓库发布的脚本及其中涉及的任何解锁和解密分析脚本,仅用于测试和学习研究,禁止用于商业用途,不能保证其合法性,准确性,完整性和有效性,请根据情况自行判断。

null 87 Nov 12, 2022
Automatic SystemVerilog linting in github actions with the help of Verible

Verible Lint Action Usage See action.yml This is a GitHub Action used to lint Verilog and SystemVerilog source files and comment erroneous lines of co

CHIPS Alliance 10 Dec 26, 2022
Automate HoYoLAB Genshin Daily Check-In Using Github Actions

Genshin Daily Check-In ?? Automate HoYoLAB Daily Check-In Using Github Actions KOR, ENG Instructions Fork the repository Go to Settings -> Secrets Cli

Leo Kim 41 Jun 24, 2022