This commit is contained in:
2024-05-17 23:31:06 +02:00
parent 754c02b173
commit 5899f9602f
4 changed files with 58 additions and 0 deletions

17
Dockerfile Normal file
View File

@@ -0,0 +1,17 @@
# Verwende die neueste LTS-Version von Node.js
FROM node:18
# Erstelle und setze das Arbeitsverzeichnis
WORKDIR /usr/src/app
# Kopiere package.json und package-lock.json (falls vorhanden)
COPY package*.json ./
# Installiere die Abhängigkeiten
RUN npm install
# Kopiere den Rest des Anwendungsverzeichnisses
COPY . .
# Definiere die Startkommandozeile für den Container
CMD [ "npm", "start" ]

1
gitignore Normal file
View File

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

27
index.js Normal file
View File

@@ -0,0 +1,27 @@
const { Client, GatewayIntentBits, ChannelType } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates] });
const token = process.env.BOT_TOKEN;
const joinToCreateChannelId = process.env.JOINTOCREATE_CHANNEL_ID;
client.once('ready', () => {
console.log('Ready!');
});
client.on('voiceStateUpdate', (oldState, newState) => {
if (newState.channelId === joinToCreateChannelId) {
newState.guild.channels.create({
name: `🔊 ${newState.member.displayName}'s Channel`,
type: ChannelType.GuildVoice,
parent: newState.channel.parentId,
}).then(channel => {
newState.member.voice.setChannel(channel);
}).catch(console.error);
}
if (oldState.channel && oldState.channel.members.size === 0 && oldState.channelId !== joinToCreateChannelId) {
oldState.channel.delete().catch(console.error);
}
});
client.login(token);

13
package.json Normal file
View File

@@ -0,0 +1,13 @@
{
"name": "join2create",
"version": "1.0.0",
"description": "Simple Discord bot with join to create feature",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"discord.js": "^14.0.0"
}
}