Merge pull request #18 from AlexIsOK/master
Fix some minor annoyances and add stage channel support
This commit is contained in:
commit
89dfb8a509
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1,3 @@
|
|||
config.json
|
||||
node_modules
|
||||
recordings
|
||||
.idea
|
||||
|
|
|
@ -6,18 +6,24 @@ const createNewChunk = () => {
|
|||
};
|
||||
|
||||
exports.enter = function(msg, channelName) {
|
||||
const voiceChannel = msg.guild.channels.cache.find(channel => channel.name === channelName);
|
||||
|
||||
if (!voiceChannel || voiceChannel.type !== 'voice')
|
||||
channelName = channelName.toLowerCase();
|
||||
|
||||
//filter out all channels that aren't voice or stage
|
||||
const voiceChannel = msg.guild.channels.cache
|
||||
.filter(c => c.type === "voice" || c.type === "stage")
|
||||
.find(channel => channel.name.toLowerCase() === channelName);
|
||||
|
||||
//if there is no voice channel at all or the channel is not voice or stage
|
||||
if (!voiceChannel || (voiceChannel.type !== 'voice' && voiceChannel.type !== 'stage'))
|
||||
return msg.reply(`The channel #${channelName} doesn't exist or isn't a voice channel.`);
|
||||
|
||||
|
||||
console.log(`Sliding into ${voiceChannel.name} ...`);
|
||||
voiceChannel.join()
|
||||
.then(conn => {
|
||||
|
||||
|
||||
const dispatcher = conn.play(__dirname + '/../sounds/drop.mp3');
|
||||
dispatcher.on('finish', () => { console.log(`Joined ${voiceChannel.name}!\n\nREADY TO RECORD\n`); });
|
||||
|
||||
|
||||
const receiver = conn.receiver;
|
||||
conn.on('speaking', (user, speaking) => {
|
||||
if (speaking) {
|
||||
|
@ -32,19 +38,13 @@ exports.enter = function(msg, channelName) {
|
|||
}
|
||||
|
||||
exports.exit = function (msg) {
|
||||
// Use optional chaining when we upgrade to Node 14.
|
||||
if (
|
||||
!(
|
||||
msg &&
|
||||
msg.guild &&
|
||||
msg.guild.voice &&
|
||||
msg.guild.voice.channel &&
|
||||
msg.guild.voice.connection
|
||||
)
|
||||
)
|
||||
//check to see if the voice cache has any connections and if there is
|
||||
//no ongoing connection (there shouldn't be undef issues with this).
|
||||
if(msg.guild.voiceStates.cache.filter(a => a.connection !== null).size !== 1)
|
||||
return;
|
||||
|
||||
const { channel: voiceChannel, connection: conn } = msg.guild.voice;
|
||||
|
||||
//make sure it's .last() not .first(). some discord js magic going on rn
|
||||
const { channel: voiceChannel, connection: conn } = msg.guild.voiceStates.cache.last();
|
||||
const dispatcher = conn.play(__dirname + "/../sounds/badumtss.mp3", { volume: 0.45 });
|
||||
dispatcher.on("finish", () => {
|
||||
voiceChannel.leave();
|
||||
|
|
13
index.js
13
index.js
|
@ -1,14 +1,23 @@
|
|||
const Discord = require('discord.js');
|
||||
const client = new Discord.Client();
|
||||
const client = new Discord.Client(
|
||||
{intents: ["GUILD_MESSAGES", "GUILD_VOICE_STATES", "GUILDS"]}
|
||||
);
|
||||
|
||||
const config = require('./config.json');
|
||||
const commands = require(`./bin/commands`);
|
||||
|
||||
//in case the bot was not configured properly
|
||||
if(!config.PREFIX || !config.BOT_TOKEN) {
|
||||
console.error("Error: the configuration file was configured properly.");
|
||||
console.error("Make sure there are no spelling mistakes.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
client.on('message', msg => {
|
||||
if (msg.content.startsWith(config.PREFIX)) {
|
||||
const commandBody = msg.content.substring(config.PREFIX.length).split(' ');
|
||||
const channelName = commandBody[1];
|
||||
|
||||
|
||||
if (commandBody[0] === ('enter') && commandBody[1]) commands.enter(msg, channelName);
|
||||
if (commandBody[0] === ('exit')) commands.exit(msg);
|
||||
}
|
||||
|
|
1411
package-lock.json
generated
1411
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -14,7 +14,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@discordjs/opus": "^0.3.2",
|
||||
"discord.js": "^12.3.1",
|
||||
"discord.js": "github:discordjs/discord.js#af00ec8970e77ea8a0afd21571eeeef9c554e1ec",
|
||||
"ffmpeg-static": "^4.2.7"
|
||||
}
|
||||
}
|
||||
|
|
5
recordings/.gitignore
vendored
Normal file
5
recordings/.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
# ignore audio-type files
|
||||
*.pcm
|
||||
*.mp3
|
||||
*.opus
|
Loading…
Reference in a new issue