This commit is contained in:
Nico Jensen 2021-12-16 00:58:46 +01:00
commit fb53fc6235
7 changed files with 2887 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules
.env

2734
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

21
package.json Normal file
View File

@ -0,0 +1,21 @@
{
"name": "discordbot_nyan9000",
"version": "1.0.0",
"description": "Discord Bot",
"main": "index.js",
"scripts": {
"start": "node src/index.js",
"dev": "nodemon src/index.js",
"deployCommands": "node src/deploy-commands.js"
},
"author": "Nico Jensen",
"license": "ISC",
"dependencies": {
"@discordjs/builders": "^0.9.0",
"@discordjs/rest": "^0.1.0-canary.0",
"discord-api-types": "^0.25.2",
"discord.js": "^13.3.1",
"dotenv": "^10.0.0",
"nodemon": "^2.0.15"
}
}

39
src/commands/createVC.js Normal file
View File

@ -0,0 +1,39 @@
const {SlashCommandBuilder} = require('@discordjs/builders')
const {MessageEmbed, Guild} = require('discord.js')
module.exports = {
data: new SlashCommandBuilder()
.setName('vc')
.setDescription('create new voice channel')
.addSubcommand(subCcommand => subCcommand.setName('Create').setDescription('Create new Voice Channel'))
.addSubcommand(subCcommand => subCcommand.setName('Rename').setDescription('Rename Voice Channel'))
.addSubcommand(subCcommand => subCcommand.setName('Delete').setDescription('Delete Voice Channel')),
async execute(interaction) {
switch(interaction.options.getSubcommand()) {
case 'Create': {
const newChannelName = `${interaction.member.displayName}'s Channel`
interaction.guild.channels.create(`${newChannelName}`, {
type: 'GUILD_VOICE',
parent: '589107550520082591',
permissionOverwrites: [{
id: interaction.member.user,
allow: ['MANAGE_CHANNELS']
}]
})
await Tags.create({
name: interaction.guild.channels.getId(`${newChannelName}`),
description: 'channelID',
username: interaction.user.username,
})
break
}
case 'Rename': {
break
}
case 'Delete': {
break
}
}
}
}

8
src/commands/ping.js Normal file
View File

@ -0,0 +1,8 @@
const {SlashCommandBuilder} = require("@discordjs/builders")
module.exports = {
data: new SlashCommandBuilder().setName("ping").setDescription("Pong!"),
async execute(interaction) {
interaction.reply("Pong!")
}
}

17
src/deploy-commands.js Normal file
View File

@ -0,0 +1,17 @@
require("dotenv").config()
const fs = require("fs")
const {REST} = require("@discordjs/rest")
const {Routes} = require("discord-api-types/v9")
const commands = []
const CommandFiles = fs.readdirSync("./src/commands").filter(file => file.endsWith(".js"))
CommandFiles.forEach(CommandFile => {
const command = require(`./commands/${CommandFile}`)
commands.push(command.data.toJSON())
})
const restClient = new REST({version: "9"}).setToken(process.env.DISCORD_BOT_TOKEN)
restClient.put(Routes.applicationGuildCommands(process.env.DISCORD_APPLICATION_ID, process.env.DISCORD_GUILD_ID),
{body: commands})
.then(() => console.log("Successully registerd commands"))

66
src/index.js Normal file
View File

@ -0,0 +1,66 @@
require("dotenv").config()
const fs = require("fs")
const {Client, Collection, Intents} = require('discord.js');
const client = new Client({intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_VOICE_STATES, Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS]});
client.commands = new Collection()
const CommandFiles = fs.readdirSync("./src/commands").filter(file => file.endsWith(".js"))
CommandFiles.forEach(CommandFile => {
const command = require(`./commands/${CommandFile}`)
client.commands.set(command.data.name, command)
})
client.once('ready', () => {
console.log(`Ready! Logged in as ${client.user.tag}! I'm on ${client.guilds.cache.size} guild(s)!`);
client.user.setActivity({
name: '2001: A Space Odyssey',
type: 'WATCHING'
})
});
client.on("interactionCreate", async(interaction) => {
if(!interaction.isCommand()) return
const command = client.commands.get(interaction.commandName)
if(command) {
try {
await command.execute(interaction)
} catch(error) {
console.error(error)
if(interaction.deferred || interaction.replied) {
interaction.editReply("Es ist ein fehler beim ausführen aufgetreten!")
} else {
interaction.reply("Es ist ein fehler beim ausführen aufgetreten!")
}
}
}
})
client.on('voiceStateUpdate', (oldState, newState) => {
if(newState.channelId === '919971427673849947') {
newState.guild.channels.create(`${newState.member.displayName}'s VC`, {
type: 'GUILD_VOICE',
parent: '589107550520082591',
permissionOverwrites: [{
id: newState.member.user,
allow: ["MANAGE_CHANNELS"]
}]
}).then(vc => {
newState.setChannel(vc);
})
}
if(oldState.channelId != null) {
if(oldState.channel.parentId == '589107550520082591') {
if(oldState.channelId != '919971427673849947') {
if(oldState.channel.members.size == 0) {
oldState.channel.delete('Delete empty Channel.')
}
}
}
}
});
client.login(process.env.DISCORD_BOT_TOKEN);