Skip to content

Instantly share code, notes, and snippets.

@wilik16
Created July 7, 2021 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilik16/6fb8bb7e2096396d963f6393651e12b2 to your computer and use it in GitHub Desktop.
Save wilik16/6fb8bb7e2096396d963f6393651e12b2 to your computer and use it in GitHub Desktop.
Discord giveaway bot sample using discord.js
// Create discord application (bot) : https://discord.com/developers/applications
// discord.js guide : https://discordjs.guide/
const Discord = require('discord.js');
const client = new Discord.Client();
const organizerId = `<enter organizer discord's id here>`;
const botToken = `<enter bot token here>`;
var participants = [];
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message => {
if (message.content === '!giveaway') {
const participant = message.author.id;
participants.push(participant);
message.channel.send(`<@${participant}> registered to the giveaway`);
} else if (message.content === `!go` && message.author.id === organizerId) {
const winner = participants[Math.floor(Math.random() * participants.length)];
message.channel.send(`Congratulations <@${winner}>!`);
}
});
client.login(botToken);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment