PEPPERBOT VOICE CHAT CAPABILITY
This commit is contained in:
parent
7d5d32fec1
commit
b92fe05718
11 changed files with 265 additions and 50 deletions
103
src/commands/soundboard.js
Normal file
103
src/commands/soundboard.js
Normal file
|
@ -0,0 +1,103 @@
|
|||
import {
|
||||
createAudioPlayer,
|
||||
createAudioResource,
|
||||
getVoiceConnection,
|
||||
joinVoiceChannel,
|
||||
} from "@discordjs/voice";
|
||||
import fs from "fs";
|
||||
import * as dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
|
||||
const prefix = process.env.PREFIX;
|
||||
|
||||
export default {
|
||||
name: "soundboard",
|
||||
description: "plays specified sound file",
|
||||
arguments: "file",
|
||||
execute(message, args) {
|
||||
const audioPlayer = createAudioPlayer();
|
||||
let proposedfilename = message.content.slice(
|
||||
prefix.length + this.name.length + 1
|
||||
);
|
||||
const files = fs.readdirSync("resources/soundboard");
|
||||
let file;
|
||||
let lsmode = false;
|
||||
let stopmode = false;
|
||||
|
||||
let possibleFilenames = {
|
||||
regular: proposedfilename,
|
||||
spaced: proposedfilename.replaceAll(" ", "_"),
|
||||
spacedmp3: proposedfilename.replaceAll(" ", "_") + ".mp3",
|
||||
mp3: proposedfilename + ".mp3",
|
||||
spacedogg: proposedfilename.replaceAll(" ", "_") + ".ogg",
|
||||
ogg: proposedfilename + ".ogg",
|
||||
spacedwav: proposedfilename.replaceAll(" ", "_") + ".wav",
|
||||
wav: proposedfilename + ".wav",
|
||||
spacedwebm: proposedfilename.replaceAll(" ", "_") + ".webm",
|
||||
webm: proposedfilename + ".webm",
|
||||
};
|
||||
for (const value of Object.values(possibleFilenames)) {
|
||||
if (files.includes(value)) {
|
||||
file = value;
|
||||
}
|
||||
}
|
||||
if (proposedfilename === "ls") {
|
||||
fs.writeFileSync("resources/soundboard/ls.txt", "");
|
||||
lsmode = true;
|
||||
for (let file = 0; file < files.length; file++) {
|
||||
if (files[file] !== "ls.txt") {
|
||||
fs.appendFileSync("resources/soundboard/ls.txt", `${files[file]}\n`);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (proposedfilename === "stop") {
|
||||
let connection = getVoiceConnection(message.guild.id);
|
||||
connection.subscribe(audioPlayer);
|
||||
audioPlayer.stop();
|
||||
message.reply("stopped audio playback");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!file && !lsmode && !stopmode) {
|
||||
message.reply(
|
||||
"unable to find your file in the soundboard folder put `ls` as your args to upload a file of all names. try replacing spaces with _s. you proposed: " +
|
||||
proposedfilename
|
||||
);
|
||||
}
|
||||
if (!lsmode) {
|
||||
const audioResource = createAudioResource(`resources/soundboard/${file}`);
|
||||
|
||||
let connection = getVoiceConnection(message.guild.id);
|
||||
if (!connection) {
|
||||
if (message.member.voice.channel) {
|
||||
let voiceState = message.member.voice;
|
||||
|
||||
let connection = joinVoiceChannel({
|
||||
channelId: voiceState.channelId,
|
||||
guildId: voiceState.guild.id,
|
||||
adapterCreator: voiceState.guild.voiceAdapterCreator,
|
||||
});
|
||||
|
||||
message.reply(`connected to <#${voiceState.channelId}>`);
|
||||
} else {
|
||||
message.reply(
|
||||
"the bot is not in a voice channel so a sound cannot be played, and you are not in a voice channel so it can't auto join. IDIOT!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
connection = getVoiceConnection(message.guild.id);
|
||||
connection.subscribe(audioPlayer);
|
||||
audioPlayer.play(audioResource);
|
||||
} else {
|
||||
message.channel.send({
|
||||
files: [
|
||||
{
|
||||
attachment: "resources/soundboard/ls.txt",
|
||||
name: "ls.txt",
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue