-
-
Save bthaw2018/d3d1a70a556458876fd64a1351e7adc2 to your computer and use it in GitHub Desktop.
Hackapalooza Discord Bot Workshop - Part 2
This file contains 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
const Discord = require('discord.js'); | |
const config = require("./config.json"); | |
const intents = new Discord.Intents(); | |
intents.add(Discord.Intents.FLAGS.GUILDS); | |
intents.add(Discord.Intents.FLAGS.GUILD_MESSAGES); | |
intents.add(Discord.Intents.FLAGS.GUILD_VOICE_STATES); | |
const client = new Discord.Client({ | |
intents: intents, | |
}); | |
client.on('ready', function (client) { | |
console.log("Ready!"); | |
let invite = client.generateInvite({ | |
scopes: ['bot'] | |
}); | |
console.log("Invite: ", invite); | |
}); | |
client.on('messageCreate', function (message) { | |
if (message.author.bot) { | |
return; | |
} | |
console.log(message.content); | |
// If user sends yes, reply with no | |
if (message.content.toLowerCase() == 'yes') { | |
message.channel.send("no") | |
.then((message) => { | |
console.log("message sent"); | |
}) | |
.catch(err => { | |
console.log("Could not send message!") | |
console.log(err.message); | |
}) | |
} else if (message.content.toLowerCase() == 'no') { | |
message.channel.send("yes") | |
.catch(function (err) { | |
console.log("Couldn't reply: ", err.message); | |
}) | |
} | |
}); | |
// move user to random VC when they join a VC | |
client.on('voiceStateUpdate', function (oldState, newState) { | |
console.log(newState.channelId); | |
if (newState.channelId && (!oldState.channelId)) { | |
// move the channel | |
let channels = newState.guild.channels.cache; | |
let voice_channels = channels.filter(channel => { | |
return ( | |
channel.type == 'GUILD_VOICE' | |
&& | |
channel.id != newState.channelId | |
); | |
}); | |
let move_to = voice_channels.randomKey(); | |
newState.setChannel(move_to) | |
.catch(function (err) { | |
console.log(err.message); | |
}); | |
} | |
}) | |
client.login(config.token); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment