Skip to content

Instantly share code, notes, and snippets.

@javilobo8
Created March 29, 2020 01:02
Show Gist options
  • Save javilobo8/3b032e0a562609da8f9c834c97efdd35 to your computer and use it in GitHub Desktop.
Save javilobo8/3b032e0a562609da8f9c834c97efdd35 to your computer and use it in GitHub Desktop.
const Discord = require('discord.js');
const bot = new Discord.Client();
var isReady = true;
async function sendAudio(connection, filepath) {
console.log('sendAudio');
return new Promise((resolve, reject) => {
const dispatcher = connection.playFile(filepath);
dispatcher.on('end', () => {
setTimeout(resolve, 2000);
});
dispatcher.on('error', reject);
});
}
async function sendMessage(message, pathfile) {
isReady = false;
message.delete();
const connection = await message.member.voiceChannel.join();
await sendAudio(connection, pathfile);
await message.member.voiceChannel.leave();
isReady = true;
}
async function handleMessage(message) {
switch (message.content) {
case 'estan': {
sendMessage(message, './estan.mp3');
break;
}
case 'estan2': {
sendMessage(message, './estan2.mp3');
break;
}
case 'estande': {
sendMessage(message, './estan-slow.mp3');
break;
}
case 'moan': {
sendMessage(message, './moan1.mp3');
break;
}
case 'willy': {
sendMessage(message, './willy.mp3');
break;
}
case 'brum': {
sendMessage(message, './brum.mp3');
break;
}
case 'hola': {
sendMessage(message, './hola.mp3');
break;
}
case 'rajoy1': {
sendMessage(message, './rajoy1.mp3');
break;
}
case 'callate': {
sendMessage(message, './callate.mp3');
break;
}
case 'k': {
sendMessage(message, './k.mp3');
break;
}
case 'look': {
sendMessage(message, './look.mp3');
break;
}
}
}
bot.on('message', handleMessage);
bot.login('<discord-token>');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment