Repository: polemikal/discord-welcome-bot Branch: main Commit: a2bc611c1fef Files: 6 Total size: 6.8 KB Directory structure: gitextract_91z_bdp_/ ├── .gitignore ├── LICENSE ├── README.md ├── app.js ├── config.json └── package.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ node_modules ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2021 polemikal Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # discord-welcome-bot A great intro sounds for Discord servers! # Setup the Project 1. Download or clone this project. 2. Setup the project options from `config.json` file. 3. Upload the required audio files in `default_files` path and enter audio files name in `config.json`. 4. Run `app.js` file from terminal. (Example run command: `node app.js`) **(!) DO NOT FORGET** You must install **FFMPEG** on your system to run. # Information **(!)** If there is something that can be added to this project or if you have found anything missing in this project, you can let us know and help us improve the project! [Let us know!](https://github.com/polemikal/discord-slash-commands-bot/issues) **(!)** This project is shared on behalf of [Serendia Squad](https://discord.com/invite/serendia). If you need any help about this project, you can join this platform and ask questions in your mind. ================================================ FILE: app.js ================================================ const { Client, VoiceChannel, GuildMember } = require("discord.js"); const fs = require("fs"); const CONFIG = JSON.parse(fs.readFileSync("./config.json", { encoding: "utf-8" })); const moment = require("moment"); require("moment-duration-format"); const Voice = new Client({ fetchAllMembers: true, disableMentions: "none" }); Voice.staffJoined = false; Voice.playingVoice = false; Voice.voiceConnection = null; Voice.channelID = null; Voice.on("ready", async() => { Voice.user.setPresence({ status: "dnd", activity: { name: CONFIG.DEFAULTS.ACTIVITY_TEXT } }); Voice.log(`Voice client \'${Voice.user.username}\' has been activated!`); const Guild = Voice.guilds.cache.get(CONFIG.DEFAULTS.GUILD_ID) || Voice.guilds.cache.first(); if(!Guild) { Voice.error("Guild not found!"); return Voice.destroy(); } const Channel = Guild.channels.cache.get(CONFIG.DEFAULTS.VOICE_CHANNEL); if(!Channel) { Voice.error("Channel not found!"); return Voice.destroy(); } Channel.join().then(connection =>{ Voice.voiceConnection = connection; Voice.channelID = Channel.id; Voice.log("The audio file is playing now...") if(!Channel.hasStaff()) playVoice(Voice); else Voice.staffJoined = true; }).catch(err => { Voice.error(`Cannot connect to voice channel (${Channel.name}) (${Channel.id}): ` + err.message) return Voice.destroy(); }); }); Voice.on("voiceStateUpdate", async(oldState, newState) => { if( newState.channelID && (oldState.channelID !== newState.channelID) && newState.member.isStaff() && newState.channelID === Voice.channelID && !newState.channel.hasStaff(newState.member) ) { Voice.staffJoined = true; return playVoice(Voice); } if( oldState.channelID && (oldState.channelID !== newState.channelID) && newState.member.isStaff() && oldState.channelID === Voice.channelID && !oldState.channel.hasStaff() ) { Voice.staffJoined = false; return playVoice(Voice); } }); Voice.login(CONFIG.TOKEN).catch(err => { Voice.error("An occured error while connecting to Voice client: " + err.message); return Voice.destroy(); }); /** * * @param {Client} Voice */ function playVoice(Voice) { try { const Path = Voice.staffJoined === true ? "./" + CONFIG.FILES.STAFF : "./" + CONFIG.FILES.WELCOME; Voice.playingVoice = true; Voice.voiceConnection.play(Path, { volume: 1 }).on("finish", async() => { Voice.playingVoice = false; if(Voice.staffJoined === true) return; playVoice(Voice); }); } catch(err) { return Voice.log("An occured error while playing voice file: " + err.message); } }; Client.prototype.log = function(content) { return console.log(`[${moment().format('YYYY-MM-DD HH:mm:ss')}] [VOICE BOT] ${content}`); }; Client.prototype.error = function(content) { return console.error(`[${moment().format('YYYY-MM-DD HH:mm:ss')}] [VOICE BOT] ERR! ${content}`); }; VoiceChannel.prototype.hasStaff = function(checkMember = false) { if(this.members.some(m => (checkMember !== false ? m.user.id !== checkMember.id : true) && !m.user.bot && m.roles.highest.position >= m.guild.roles.cache.get(CONFIG.DEFAULTS.MIN_STAFF_ROLE).position)) return true; // m.roles.highest.position >= this.guild.roles.cache.get(CONFIG.DEFAULTS.MIN_STAFF_ROLE).position return false; } VoiceChannel.prototype.getStaffs = function(checkMember = false) { return this.members.filter(m => (checkMember !== false ? m.user.id !== checkMember.id : true) && !m.user.bot && m.roles.highest.position >= m.guild.roles.cache.get(CONFIG.DEFAULTS.MIN_STAFF_ROLE).position).size } GuildMember.prototype.isStaff = function() { if( !this.user.bot && ([...CONFIG.DEFAULTS.AUTHORS].includes(this.id) || this.hasPermission("ADMINISTRATOR") || this.roles.highest.position >= this.guild.roles.cache.get(CONFIG.DEFAULTS.MIN_STAFF_ROLE).position ) ) return true; return false; } ================================================ FILE: config.json ================================================ { "DEFAULTS": { "AUTHORS": [], "ACTIVITY_TEXT": "Polemikal Voice System", "GUILD_ID": "", "VOICE_CHANNEL": "", "MIN_STAFF_ROLE": "" }, "FILES": { "WELCOME": "default_files/.mp3", "STAFF": "default_files/.mp3" }, "TOKEN": "BOT_TOKEN" } ================================================ FILE: package.json ================================================ { "name": "dark-voice-bots", "version": "1.0.0", "description": "", "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "polemikal", "license": "ISC", "dependencies": { "@discordjs/opus": "^0.3.3", "discord.js": "^12.5.1", "fs": "0.0.1-security", "moment": "^2.29.1", "moment-duration-format": "^2.3.2", "opusscript": "0.0.7" } }