CSUL Discord Bot

Overview

Cruzeiro

This is the same old bot running on the Discord Server of CSUL, but i've changed the code. It's better now.

How i did

The bot is now running on Heroku servers, using only free features. There are some new commands on Heroku CLI that can be a problem if you don't pay attention. I'll list some things i almost miss while read the documentations, on the first attempt to host this bot.

→ Create Python reference

  • Heroku won't able the buildpacks if they don't be referred. I used heroku buildpacks:set heroku/python to set it.
  • This can be configurated at the heroku create command, creating the app and setting the buildpack inside.

→ Set Procfile and requirements

  • These two files must be created at the same directory as the .py script. The Procfile can't have a extension, and will contain the web/worker dynos to actually connect the app to Heroku.
  • I downloaded gunicorn to use these dynos properly, but i don't really needed it at all. All i had to do was run the dynos with the python parameter.

Procfile

  • The requirements.txt has to contain all the packages/versions that are being used on the application. I also forgot to put a "discord==1.0.1" line to invoke the main discord package.
  • On Heroku CLI, i had to make a heroku ps:scale web=1 worker=1 after update the Procfile. This line sets the amount of dynos that the application will use. Also, i had to enable the options of web and worker (after commit) on Heroku dashboard resources page.

Heroku Resources

→ Switch branches and deploy

  • Yes, i was in the remote branch master, which was used to be the default branch for Heroku. However, i had to change it to the main branch, using the command line git checkout main. After doing this, the code was able to actually being pushed.
  • The code i edit is on master branch (Github), i just switch to main everytime i need to push it to Heroku. So, the first time i deployed, the bot was pinging each 30 seconds, and logging twice. The problem here was the unnecessary use of gunicorn, which runs a new server online, so i just had to remove the line reference "web: gunicorn main:app" of the Procfile, replacing by the python main.py that was mentioned before. I've added the worker dyno, edited some lines of the code and pushed it. The bot is on, working fine.

Online

I'll update every change or issue on the application, this .readme just tells the things i did to solve some problems. If there's something that can be changed or solved in a better way, i can edit the text anytime, so it can be helpful to others.

Texto em Português

Cruzeiro

Esse é o mesmo bot antigo que foi escrito em C#, rodando no servidor do Discord da CSUL, mas eu mudei o código. Está melhor agora.

Como eu fiz

O bot está rodando agora nos servidores da Heroku, usando só recursos gratuitos. Tem alguns novos comandos na CLI da Heroku que podem causar problemas se você não prestar atenção. Eu vou listar aqui algumas coisas que eu quase esqueci enquanto lia as documentações, na primeira vez que tentei hospedar o bot.

→ Criar referência do Python

  • A Heroku não vai habilitar os buildpacks se eles não forem referenciados. Eu usei o heroku buildpacks:set heroku/python pra setar isso.
  • Isso pode ser configurado no comando heroku create, criando o aplicativo com o buildpack já inserido.

→ Configurar Procfile e os requirements

  • Esses dois arquivos precisam ser criados no mesmo diretório do arquivo .py. O Procfile não pode ter extensão, e vai receber os dynos web/worker pra conectar a aplicação com a Heroku.
  • Eu instalei o gunicorn pra usar os dynos, mas no final eu não precisei dele. Só passei o parâmetro python para rodá-los.

Procfile

  • O requirements.txt precisa ter todos os packages (comk as versões) que estão sendo usadas no app. Eu também esqueci de passar o parâmetro "discord==1.0.1" para chamar o pacote principal do Discord.
  • Na linha de comando, eu tive que mandar um heroku ps:scale web=1 worker=1 depois de editar o Procfile. Esse comando configura a quantidade de dynos que vão ser usados. Depois eu também precisei habilitar os dois dynos na página de resources da Heroku, dentro do Dashboard da aplicação.

Heroku Resources

→ Trocar branches e fazer o deploy

  • Sim, eu estava no branch master, que era o branch padrão da Heroku. Entretanto, eu precisei mudar para o main branch com o comando git checkout main. Depois de fazer isso, eu pude executar o git push.
  • O código que eu edito está no master branch (Github), eu só troco para o main toda vez que vou enviar o push para a Heroku. Da primeira vez que eu fiz o deploy, o bot estava dando ping a cada 30 segundos, e logando duas vezes num único push. O problema aqui era o uso desnecessário do gunicorn,que roda um novo servidor online, então eu precisei remover a linha "web: gunicorn main:app" no Procfile, alternando para python main.py que eu havia mencionado antes. Eu adicionei o dyno worker, editei algumas linhas no código principal e executei o git push. O bot está online, funcionando perfeitamente.

Online

Eu vou atualizar toda mudança ou problema da aplicação, esse readme só conta os métodos que eu usei pra resolver alguns problemas. Se tem algo que pode ser mudado ou resolvido de uma maneira melhor, eu posso editar esse texto a qualquer hora, para ser útil para outras pessoas.

You might also like...
SongLink Discord Bot - Discord bot to share music links easily

SongLink_Discord_Bot Discord bot to share music links easily. Take a link from y

Anime-Discord-Bot - Lightweight anime searching Discord bot supported by the AnilistPython library (anilist.co APIv2 wrapper))
VoiceMaster-Discord-Bot - Fork from original Discord bot with max channel limit, staff role and more

VoiceMaster VoiceMaster is a discord bot created to change the way servers work,

A discord Server Bot made with Python, This bot helps people feel better by inspiring them with motivational quotes or by responding with a great message, also the users of the server can create custom messages by telling the bot with Commands.
A discord Server Bot made with Python, This bot helps people feel better by inspiring them with motivational quotes or by responding with a great message, also the users of the server can create custom messages by telling the bot with Commands.

A discord Server Bot made with Python, This bot helps people feel better by inspiring them with motivational quotes or by responding with a great message, also the users of the server can create custom messages by telling the bot with Commands.

Aqui está disponível GRATUITAMENTE, um bot de discord feito em python, saiba que, terá que criar seu bot como aplicação, e utilizar seu próprio token, e lembrando, é um bot básico, não se utiliza Cogs nem slash commands nele!

BotDiscordPython Aqui está disponível GRATUITAMENTE, um bot de discord feito em python, saiba que, terá que criar seu bot como aplicação, e utilizar s

Automate TikTok follower bot, like bot, share bot, view bot and more using selenium
Automate TikTok follower bot, like bot, share bot, view bot and more using selenium

Zefoy TikTok Automator Automate TikTok follower bot, like bot, share bot, view bot and more using selenium. Click here to report bugs. Usage Download

A Discord BOT that uses Google Sheets for storing the roles and permissions of a discord server.

Discord Role Manager Bot Role Manager is a discord BOT that utilizes Google Sheets for the organization of a server's hierarchy and permissions. Detai

MusicBot is the original Discord music bot written for Python 3.5+, using the discord.py library
MusicBot is the original Discord music bot written for Python 3.5+, using the discord.py library

The original MusicBot for Discord (formerly SexualRhinoceros/MusicBot)

Owner
Operaho
Deducing the future;
Operaho
It's a Discord bot to control your PC using your Discord Channel or using Reco: Discord PC Remote Controller App.

Reco PC Server Reco PC Server is a cross platform PC Controller Discord Bot which is a modified and improved version of Chimera for Reco-Discord PC Re

Arvinth Krishna 12 Aug 31, 2022
A small and fun Discord Bot that is written in Python and discord-interactions (with discord.py)

Articuno (discord-interactions) A small and fun Discord Bot that is written in Python and discord-interactions (with discord.py) Get started If you wa

Blue 8 Dec 26, 2022
Discord bot script for sending multiple media files to a discord channel according to discord limitations.

Discord Bulk Image Sending Bot Send bulk images to Discord channel. This is a bot script that will allow you to send multiple images to Discord channe

Nikola Arbov 1 Jan 13, 2022
An Open-Source Discord bot created to provide basic functionality which should be in every discord guild. We use this same bot with additional configurations for our guilds.

A Discord bot completely written to be taken from the source and built according to your own custom needs. This bot supports some core features and is

Tesseract Coding 14 Jan 11, 2022
Discord ToolBox is a discord bot developed by DJD320 created for the purpose of having some convenient tools in the form of a single bot.

Discord ToolBox Discord ToolBox is a discord bot developed by DJD320 created for the purpose of having some convenient tools in the form of a single b

null 3 Aug 7, 2021
Linky bot, A open-source discord bot that allows you to add links to ur website, youtube url, etc for the people all around discord to see!

LinkyBot Linky bot, An open-source discord bot that allows you to add links to ur website, youtube url, etc for the people all around discord to see!

AlexyDaCoder 1 Sep 20, 2022
Image-Bot-Discord - This Is a discord bot that shows the specific image you search from Google

Advanced Discord.py Image Bot CREDITS Made by RLX and Mathiscool README by Milrato Installation Guide in .env Adjust the TOKEN python main.py to start

RLX 3 Jan 16, 2022
Discord.py-Bot-Template - Discord Bot Template with Python 3.x

Discord Bot Template with Python 3.x This is a template for creating a custom Di

Keagan Landfried 3 Jul 17, 2022
Example-bot-discord - Example bot discord xD

example-python-bot-discord Clone this repository Grab a token on Discord's devel

Amitminer 1 Mar 14, 2022
YouTube-Discord-Bot - Discord Bot to Search YouTube

YouTube Bot Info YouTube Bot is a discord bot where you can search for anything

Riceblades11 10 Mar 5, 2022