Skip to content

Instantly share code, notes, and snippets.

@Galitan-dev
Forked from Raraph84/index.js
Last active July 30, 2023 14:55
Show Gist options
  • Save Galitan-dev/4ad2501e43bd604f1c514898b7e5705d to your computer and use it in GitHub Desktop.
Save Galitan-dev/4ad2501e43bd604f1c514898b7e5705d to your computer and use it in GitHub Desktop.
Discord Badge Bot

Discord Badge Bot

Ceci est une fourchette du Badge Bot de Raraph.
Elle permet de le lancer dans un Contenaire Docker.

Utilisation

Sauvegarder le token discord:

$ read -p "Entrez le token du bot: " TOKEN

Télécharger et construire l'image docker localement

$ curl -L https://gist.github.com/Galitan-dev/4ad2501e43bd604f1c514898b7e5705d/raw/Dockerfile | docker build -t badge-bot:latest --build-arg TOKEN=$TOKEN -

Lancer le bot

$ docker run --rm --name badge-bot -d badge-bot:latest

Déboggage

Voir les logs:

$ docker logs badge-bot

M'envoyer un message sur discord: @galitan

FROM node:alpine3.18 AS base
LABEL version="1.0"
LABEL author="Galitan-dev"
WORKDIR /run
FROM base AS dependencies
RUN [ "npm", "install", "discord.js" ]
FROM dependencies AS code
ADD https://gist.github.com/Galitan-dev/4ad2501e43bd604f1c514898b7e5705d/raw/index.js /run/index.js
FROM code AS env
ARG TOKEN
ENV TOKEN=${TOKEN}
FROM env AS prod
ENTRYPOINT [ "/usr/local/bin/node" ]
CMD [ "/run/index.js" ]
const { Client } = require("discord.js");
const bot = new Client({ intents: ["Guilds"] });
console.log("Connexion au bot...");
bot.login(process.env.TOKEN)
.then(() => console.log("Connecté au bot !"))
.catch((error) => console.log("Impossible de se connecter au bot - " + error));
bot.on("ready", async () => {
await bot.application.commands.set([
{
name: "ping",
description: "Pong!"
}
]);
console.log("Le bot est prêt !");
});
bot.on("interactionCreate", (interaction) => {
if (!interaction.isCommand()) return;
if (interaction.commandName === "ping")
interaction.reply("Pong!");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment