mirror of
https://github.com/arthur-pbty/LazyBot.git
synced 2026-06-19 13:46:42 +02:00
finish organization event/command & add guild command in folder commands
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
const { Events } = require("discord.js");
|
||||
const db = require("../db");
|
||||
|
||||
module.exports = {
|
||||
name: Events.VoiceStateUpdate,
|
||||
async execute(client, oldState, newState) {
|
||||
if (newState.member.user.bot) return;
|
||||
|
||||
const guildId = newState.guild.id;
|
||||
|
||||
db.get(
|
||||
"SELECT enabled, role_id, exclude_channel_ids FROM autorole_vocal_config WHERE guild_id = ?",
|
||||
[guildId],
|
||||
(err, row) => {
|
||||
if (err || !row || !row.enabled) return;
|
||||
|
||||
let excludeChannelIds = [];
|
||||
try {
|
||||
excludeChannelIds = row.exclude_channel_ids
|
||||
? JSON.parse(row.exclude_channel_ids)
|
||||
: [];
|
||||
} catch (err) {
|
||||
console.error("Erreur parsing exclude_channel_ids", err);
|
||||
excludeChannelIds = [];
|
||||
}
|
||||
|
||||
const role = newState.guild.roles.cache.get(row.role_id);
|
||||
if (!role) return;
|
||||
|
||||
// User joins a voice channel and it's not excluded et a pas déjà le rôle
|
||||
if (newState.channelId && !excludeChannelIds.includes(newState.channelId) && !newState.member.roles.cache.has(role.id)) {
|
||||
newState.member.roles.add(role);
|
||||
}
|
||||
// User leaves a voice channel or joins an excluded one
|
||||
else if (!newState.channelId || excludeChannelIds.includes(newState.channelId)) {
|
||||
newState.member.roles.remove(role);
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user