generated from Baipyrus/DiscordJS-Template
Compare commits
No commits in common. "3a2073f61f0ac1683e47fcd1be3c8ca344287370" and "7a9c2441a3d13af32188275094f76bf6cff50f80" have entirely different histories.
3a2073f61f
...
7a9c2441a3
@ -1,15 +1,13 @@
|
||||
import { ChannelType, Events } from 'discord.js';
|
||||
import { Events } from 'discord.js';
|
||||
import { VoiceChannel } from '../../database.js';
|
||||
|
||||
export const name = Events.ChannelDelete;
|
||||
export async function execute(channel) {
|
||||
if (channel.type !== ChannelType.GuildVoice) return;
|
||||
|
||||
// Delete channel entry once channel is deleted itself
|
||||
const count = await VoiceChannel.destroy({
|
||||
where: {
|
||||
id: channel.id
|
||||
}
|
||||
});
|
||||
if (count > 0) console.info(`[INFO] Custom VC entry with ID '${channel.id}' was destroyed.`);
|
||||
if (count > 0) console.info(`[INFO] Custom VC with ID '${channel.id}' was deleted.`);
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ const vcPermissionOverwrites = [
|
||||
PermissionFlagsBits.ViewChannel,
|
||||
PermissionFlagsBits.MuteMembers,
|
||||
PermissionFlagsBits.MoveMembers,
|
||||
PermissionFlagsBits.ManageRoles,
|
||||
PermissionFlagsBits.Connect,
|
||||
PermissionFlagsBits.Stream,
|
||||
PermissionFlagsBits.UseVAD,
|
||||
@ -77,8 +78,7 @@ const leftVoiceChat = async (state) => {
|
||||
|
||||
export const name = Events.VoiceStateUpdate;
|
||||
export async function execute(oldState, newState) {
|
||||
await leftVoiceChat(oldState)
|
||||
if (!newState.channel) return;
|
||||
if (!newState.channel) return await leftVoiceChat(oldState);
|
||||
|
||||
// Find channel by id, return if not registered for customs
|
||||
const createCh = await VoiceChannel.findOne({
|
||||
|
24
shared.js
24
shared.js
@ -1,11 +1,8 @@
|
||||
import { join } from 'path';
|
||||
import { Op } from 'sequelize';
|
||||
import { config } from 'dotenv';
|
||||
import { readdir } from 'fs/promises';
|
||||
import { Message, RoleEmojiPair } from './database.js';
|
||||
|
||||
config();
|
||||
|
||||
export const removeSelfRoles = async (interaction, id) => {
|
||||
// Try deleting message from database
|
||||
const count = await Message.destroy({
|
||||
@ -56,23 +53,6 @@ const saveMessageData = async (id, role, emoji) => {
|
||||
await RoleEmojiPair.create({ message: id, role: role.id, emoji });
|
||||
};
|
||||
|
||||
const editMessage = async (message, role, emoji) => {
|
||||
if (message.author.id !== process.env.CLIENT) return;
|
||||
|
||||
// Find out whether to pad message or already present
|
||||
let padding = '\n';
|
||||
const reps = await RoleEmojiPair.findAll({ where: { message: message.id } });
|
||||
if (reps.length === 0) padding += '\n';
|
||||
|
||||
// Get old and build new content of message
|
||||
const current = message.content;
|
||||
const next = current + padding +
|
||||
`React with ${emoji} to receive <@&${role.id}>!`;
|
||||
|
||||
// Set message by editing
|
||||
await message.edit(next);
|
||||
};
|
||||
|
||||
export const addSelfRoles = async (interaction, msgID, role, emoji) => {
|
||||
const { channel } = interaction;
|
||||
|
||||
@ -81,10 +61,6 @@ export const addSelfRoles = async (interaction, msgID, role, emoji) => {
|
||||
// Get message by id
|
||||
const message = await channel.messages.fetch(msgID);
|
||||
|
||||
step = 'edit';
|
||||
// Try editing message to explain pair
|
||||
await editMessage(message, role, emoji);
|
||||
|
||||
step = 'save data from';
|
||||
await saveMessageData(msgID, role, emoji);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user