Created
July 7, 2021 03:34
-
-
Save wilik16/6fb8bb7e2096396d963f6393651e12b2 to your computer and use it in GitHub Desktop.
Discord giveaway bot sample using discord.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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