generated from Baipyrus/DiscordJS-Template
Compare commits
No commits in common. "f3e2715703f188fe26224b282728c5029fcc2e49" and "d0ec7fbb6c6897807231840d1cce8dc3283ce56b" have entirely different histories.
f3e2715703
...
d0ec7fbb6c
@ -1,4 +1,4 @@
|
|||||||
import { ChannelType, SlashCommandBuilder } from 'discord.js';
|
import { SlashCommandBuilder } from 'discord.js';
|
||||||
import { VoiceChannel } from '../../../database.js';
|
import { VoiceChannel } from '../../../database.js';
|
||||||
|
|
||||||
export const data = new SlashCommandBuilder()
|
export const data = new SlashCommandBuilder()
|
||||||
@ -39,22 +39,13 @@ export async function execute(interaction) {
|
|||||||
|
|
||||||
step = 'create';
|
step = 'create';
|
||||||
// Create new channel
|
// Create new channel
|
||||||
const channel = await guild.channels.create({
|
const channel = await guild.create({
|
||||||
name, type: ChannelType.GuildVoice
|
name, type: ChannelType.GuildVoice
|
||||||
});
|
});
|
||||||
|
|
||||||
// Save channel data
|
// Save channel data
|
||||||
step = 'save';
|
step = 'save';
|
||||||
await VoiceChannel.create({
|
await VoiceChannel.create({ id: channel.id });
|
||||||
id: channel.id,
|
|
||||||
create: true
|
|
||||||
});
|
|
||||||
|
|
||||||
// Reply success to acknowledge command
|
|
||||||
await interaction.reply({
|
|
||||||
content: `Successfully created channel!`,
|
|
||||||
ephemeral: true
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'register': {
|
case 'register': {
|
||||||
@ -67,13 +58,7 @@ export async function execute(interaction) {
|
|||||||
|
|
||||||
// Save channel data
|
// Save channel data
|
||||||
step = 'save';
|
step = 'save';
|
||||||
await VoiceChannel.create({ id, create: true });
|
await VoiceChannel.create({ id });
|
||||||
|
|
||||||
// Reply success to acknowledge command
|
|
||||||
await interaction.reply({
|
|
||||||
content: `Successfully registered channel!`,
|
|
||||||
ephemeral: true
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
import { ChannelType, Events, PermissionsBitField } from 'discord.js';
|
import { ChannelType, Events, PermissionsBitField } from 'discord.js';
|
||||||
import { VoiceChannel } from '../../database.js';
|
|
||||||
|
|
||||||
const getchannel = async (member, channels) => {
|
export const name = Events.VoiceStateUpdate;
|
||||||
// Check database for existing channel
|
export async function execute(_, state) {
|
||||||
const ownCh = await VoiceChannel.findOne({
|
if (!state.channel) return;
|
||||||
where: {
|
|
||||||
owner: member.user.id
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (ownCh !== null) {
|
|
||||||
return await channels.fetch(ownCh.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create private channel with all permissions
|
// Extract user data
|
||||||
|
const member = state.member;
|
||||||
const name = member.user.username;
|
const name = member.user.username;
|
||||||
|
|
||||||
|
// Extract channel data
|
||||||
|
const channels = state.guild.channels;
|
||||||
|
try {
|
||||||
|
// Create private channel with all permissions
|
||||||
const chName = `${name}${name.endsWith('s') ? "'" : "'s"} channel`;
|
const chName = `${name}${name.endsWith('s') ? "'" : "'s"} channel`;
|
||||||
const privCh = await channels.create({
|
const privCh = await channels.create({
|
||||||
name: chName,
|
name: chName,
|
||||||
@ -28,43 +26,11 @@ const getchannel = async (member, channels) => {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
// Save newly created channel
|
|
||||||
await VoiceChannel.create({
|
|
||||||
id: privCh.id,
|
|
||||||
owner: member.user.id
|
|
||||||
})
|
|
||||||
|
|
||||||
return privCh;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const name = Events.VoiceStateUpdate;
|
|
||||||
export async function execute(_, state) {
|
|
||||||
if (!state.channel) return;
|
|
||||||
|
|
||||||
// Find channel by id, return if not registered for customs
|
|
||||||
const createCh = await VoiceChannel.findOne({
|
|
||||||
where: {
|
|
||||||
id: state.channel.id,
|
|
||||||
create: true,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (createCh === null) return;
|
|
||||||
|
|
||||||
// Extract user data
|
|
||||||
const member = state.member;
|
|
||||||
|
|
||||||
// Extract channel data
|
|
||||||
const channels = state.guild.channels;
|
|
||||||
let step = 'create';
|
|
||||||
try {
|
|
||||||
const privCh = await getchannel(member, channels);
|
|
||||||
|
|
||||||
step = 'move to';
|
|
||||||
// Move user to private channel
|
// Move user to private channel
|
||||||
await state.setChannel(privCh);
|
await state.setChannel(privCh);
|
||||||
console.info(`[INFO] User '${name}' created private channel with ID ${privCh.id}.`);
|
console.info(`[INFO] User '${name}' created private channel with ID ${privCh.id}.`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
await member.send(`Failed to ${step} channel! Please contact server staff.`);
|
await member.send('Could no create or move to channel! Please contact server staff.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,14 +5,6 @@ export default function(sequelize) {
|
|||||||
id: {
|
id: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
primaryKey: true
|
primaryKey: true
|
||||||
},
|
|
||||||
create: {
|
|
||||||
type: DataTypes.BOOLEAN
|
|
||||||
},
|
|
||||||
owner: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
defaultValue: false,
|
|
||||||
allowNull: true
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user