generated from Baipyrus/DiscordJS-Template
Compare commits
6 Commits
ddcec60be6
...
cb56dded3b
Author | SHA1 | Date | |
---|---|---|---|
cb56dded3b | |||
7fa972b411 | |||
70d183e1ef | |||
d272bdb15e | |||
c66cff1d21 | |||
474a35a736 |
@ -2,6 +2,7 @@ import { Message } from '../../database.js';
|
|||||||
import { ApplicationCommandType, ContextMenuCommandBuilder } from 'discord.js';
|
import { ApplicationCommandType, ContextMenuCommandBuilder } from 'discord.js';
|
||||||
|
|
||||||
export const data = new ContextMenuCommandBuilder()
|
export const data = new ContextMenuCommandBuilder()
|
||||||
|
.setDMPermission(false)
|
||||||
.setName('Register self roles')
|
.setName('Register self roles')
|
||||||
.setType(ApplicationCommandType.Message);
|
.setType(ApplicationCommandType.Message);
|
||||||
export async function execute(interaction) {
|
export async function execute(interaction) {
|
30
commands/admin/ctx_register_self_roles.js
Normal file
30
commands/admin/ctx_register_self_roles.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { Message } from '../../database.js';
|
||||||
|
import { ApplicationCommandType, ContextMenuCommandBuilder } from 'discord.js';
|
||||||
|
|
||||||
|
export const data = new ContextMenuCommandBuilder()
|
||||||
|
.setDMPermission(false)
|
||||||
|
.setName('Register self roles')
|
||||||
|
.setType(ApplicationCommandType.Message);
|
||||||
|
export async function execute(interaction) {
|
||||||
|
const id = interaction.targetMessage.id;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Create database entry
|
||||||
|
await Message.create({ id });
|
||||||
|
|
||||||
|
// Reply successfully to acknowledge command
|
||||||
|
await interaction.reply({
|
||||||
|
content: `Successfully saved data from message! Add roles to it with reference ID '${id}'.`,
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.info(`[INFO] New self roles on message with ID: '${id}'.`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
// Reply failed to acknowledge command
|
||||||
|
await interaction.reply({
|
||||||
|
content: 'Failed to save data from message!',
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -113,6 +113,7 @@ const addSelfRoles = async (interaction) => {
|
|||||||
|
|
||||||
export const data = new SlashCommandBuilder()
|
export const data = new SlashCommandBuilder()
|
||||||
.setName('self_roles')
|
.setName('self_roles')
|
||||||
|
.setDMPermission(false)
|
||||||
.setDescription('Manages reactions for self roles.')
|
.setDescription('Manages reactions for self roles.')
|
||||||
.addSubcommand(subcommand =>
|
.addSubcommand(subcommand =>
|
||||||
subcommand
|
subcommand
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
import {
|
|
||||||
ActionRowBuilder,
|
|
||||||
ModalBuilder,
|
|
||||||
SlashCommandBuilder,
|
|
||||||
TextInputBuilder,
|
|
||||||
TextInputStyle
|
|
||||||
} from 'discord.js';
|
|
||||||
|
|
||||||
export const data = new SlashCommandBuilder()
|
|
||||||
.setName('login')
|
|
||||||
.setDescription('Opens a login pop-up.');
|
|
||||||
export async function modalSubmit(interaction) {
|
|
||||||
await interaction.reply({
|
|
||||||
content: 'Successfully submitted Form!',
|
|
||||||
ephemeral: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
export async function execute(interaction) {
|
|
||||||
const modal = new ModalBuilder()
|
|
||||||
.setCustomId('login-modal')
|
|
||||||
.setTitle('Login Form');
|
|
||||||
|
|
||||||
const user = new ActionRowBuilder().addComponents(
|
|
||||||
new TextInputBuilder()
|
|
||||||
.setCustomId('user')
|
|
||||||
.setLabel('Enter username:')
|
|
||||||
.setStyle(TextInputStyle.Short)
|
|
||||||
.setRequired(true)
|
|
||||||
);
|
|
||||||
const password = new ActionRowBuilder().addComponents(
|
|
||||||
new TextInputBuilder()
|
|
||||||
.setCustomId('password')
|
|
||||||
.setLabel('Enter password:')
|
|
||||||
.setStyle(TextInputStyle.Short)
|
|
||||||
.setRequired(true)
|
|
||||||
);
|
|
||||||
|
|
||||||
modal.addComponents(user, password);
|
|
||||||
|
|
||||||
await interaction.showModal(modal);
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
import {
|
|
||||||
ActionRowBuilder,
|
|
||||||
ComponentType,
|
|
||||||
RoleSelectMenuBuilder,
|
|
||||||
SlashCommandBuilder
|
|
||||||
} from 'discord.js';
|
|
||||||
|
|
||||||
export const data = new SlashCommandBuilder()
|
|
||||||
.setName('role_selector')
|
|
||||||
.setDMPermission(false)
|
|
||||||
.setDescription('Provides a role selector.');
|
|
||||||
export async function execute(interaction) {
|
|
||||||
const roles = await interaction.guild.roles.fetch();
|
|
||||||
const choices = roles
|
|
||||||
.filter((r) => r.name.startsWith('test'))
|
|
||||||
.map((r) => r.id);
|
|
||||||
|
|
||||||
const button = new RoleSelectMenuBuilder()
|
|
||||||
.setMinValues(1)
|
|
||||||
.setMaxValues(25)
|
|
||||||
.setCustomId('role')
|
|
||||||
.setDefaultRoles(choices)
|
|
||||||
.setPlaceholder('Select at least one role.');
|
|
||||||
|
|
||||||
const row = new ActionRowBuilder()
|
|
||||||
.addComponents(button);
|
|
||||||
|
|
||||||
const response = await interaction.reply({
|
|
||||||
components: [row],
|
|
||||||
ephemeral: true
|
|
||||||
});
|
|
||||||
|
|
||||||
const collector = response.createMessageComponentCollector({
|
|
||||||
componentType: ComponentType.RoleSelect,
|
|
||||||
time: 120_000
|
|
||||||
});
|
|
||||||
|
|
||||||
collector.on('collect', async (i) => {
|
|
||||||
const selection = roles
|
|
||||||
.filter((r) => i.values.includes(r.id))
|
|
||||||
.map((r) => r.name)
|
|
||||||
.join(', ');
|
|
||||||
await i.reply({
|
|
||||||
content: `You have selected: "${selection}".`,
|
|
||||||
ephemeral: true
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
@ -35,9 +35,19 @@ export async function execute(reaction, user) {
|
|||||||
// Fetch role from guild
|
// Fetch role from guild
|
||||||
const guild = reaction.message.guild;
|
const guild = reaction.message.guild;
|
||||||
const role = await guild.roles.fetch(rep.role);
|
const role = await guild.roles.fetch(rep.role);
|
||||||
if (role === null) return;
|
// Role not found
|
||||||
|
if (role === null) {
|
||||||
|
await user.send('Could not fetch role! Please contact server staff.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
// Add role to user
|
// Add role to user
|
||||||
await guild.members.addRole({ role, user });
|
await guild.members.addRole({ role, user });
|
||||||
console.info(`[INFO] Added role with id '${role.id}' to user '${user.username}'.`);
|
console.info(`[INFO] Added role with id '${role.id}' to user '${user.username}'.`);
|
||||||
|
} catch (error) {
|
||||||
|
// Missing permissions
|
||||||
|
console.error(error);
|
||||||
|
await user.send('Unable to assign role. Please contact server staff.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,9 +31,19 @@ export async function execute(reaction, user) {
|
|||||||
// Fetch role from guild
|
// Fetch role from guild
|
||||||
const guild = reaction.message.guild;
|
const guild = reaction.message.guild;
|
||||||
const role = await guild.roles.fetch(rep.role);
|
const role = await guild.roles.fetch(rep.role);
|
||||||
if (role === null) return;
|
// Role not found
|
||||||
|
if (role === null) {
|
||||||
|
await user.send('Could not fetch role! Please contact server staff.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Add role to user
|
try {
|
||||||
|
// Remove role from user
|
||||||
await guild.members.removeRole({ role, user });
|
await guild.members.removeRole({ role, user });
|
||||||
console.info(`[INFO] Removed role with id '${role.id}' from user '${user.username}'.`);
|
console.info(`[INFO] Removed role with id '${role.id}' from user '${user.username}'.`);
|
||||||
|
} catch (error) {
|
||||||
|
// Missing permissions
|
||||||
|
console.error(error);
|
||||||
|
await user.send('Unable to retract role. Please contact server staff.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user