Merge pull request #18 from AlexIsOK/master

Fix some minor annoyances and add stage channel support
This commit is contained in:
Cheb 2021-05-08 12:42:35 +05:30 committed by GitHub
commit 89dfb8a509
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 738 additions and 731 deletions

2
.gitignore vendored
View file

@ -1,3 +1,3 @@
config.json config.json
node_modules node_modules
recordings .idea

View file

@ -6,9 +6,15 @@ const createNewChunk = () => {
}; };
exports.enter = function(msg, channelName) { exports.enter = function(msg, channelName) {
const voiceChannel = msg.guild.channels.cache.find(channel => channel.name === channelName); channelName = channelName.toLowerCase();
if (!voiceChannel || voiceChannel.type !== 'voice') //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.`); return msg.reply(`The channel #${channelName} doesn't exist or isn't a voice channel.`);
console.log(`Sliding into ${voiceChannel.name} ...`); console.log(`Sliding into ${voiceChannel.name} ...`);
@ -32,19 +38,13 @@ exports.enter = function(msg, channelName) {
} }
exports.exit = function (msg) { exports.exit = function (msg) {
// Use optional chaining when we upgrade to Node 14. //check to see if the voice cache has any connections and if there is
if ( //no ongoing connection (there shouldn't be undef issues with this).
!( if(msg.guild.voiceStates.cache.filter(a => a.connection !== null).size !== 1)
msg &&
msg.guild &&
msg.guild.voice &&
msg.guild.voice.channel &&
msg.guild.voice.connection
)
)
return; 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 }); const dispatcher = conn.play(__dirname + "/../sounds/badumtss.mp3", { volume: 0.45 });
dispatcher.on("finish", () => { dispatcher.on("finish", () => {
voiceChannel.leave(); voiceChannel.leave();

View file

@ -1,9 +1,18 @@
const Discord = require('discord.js'); 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 config = require('./config.json');
const commands = require(`./bin/commands`); 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 => { client.on('message', msg => {
if (msg.content.startsWith(config.PREFIX)) { if (msg.content.startsWith(config.PREFIX)) {
const commandBody = msg.content.substring(config.PREFIX.length).split(' '); const commandBody = msg.content.substring(config.PREFIX.length).split(' ');

1411
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -14,7 +14,7 @@
}, },
"dependencies": { "dependencies": {
"@discordjs/opus": "^0.3.2", "@discordjs/opus": "^0.3.2",
"discord.js": "^12.3.1", "discord.js": "github:discordjs/discord.js#af00ec8970e77ea8a0afd21571eeeef9c554e1ec",
"ffmpeg-static": "^4.2.7" "ffmpeg-static": "^4.2.7"
} }
} }

5
recordings/.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
# ignore audio-type files
*.pcm
*.mp3
*.opus