generated from Baipyrus/DiscordJS-Template
Compare commits
No commits in common. "cb56dded3b6323bf372a168f79802fc7022967ec" and "ddcec60be671b51853e9bb4d3b1c1f1a84599b86" have entirely different histories.
cb56dded3b
...
ddcec60be6
@ -1,30 +0,0 @@
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ 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) {
|
@ -113,7 +113,6 @@ const addSelfRoles = async (interaction) => {
|
||||
|
||||
export const data = new SlashCommandBuilder()
|
||||
.setName('self_roles')
|
||||
.setDMPermission(false)
|
||||
.setDescription('Manages reactions for self roles.')
|
||||
.addSubcommand(subcommand =>
|
||||
subcommand
|
||||
|
41
commands/utility/login.js
Normal file
41
commands/utility/login.js
Normal file
@ -0,0 +1,41 @@
|
||||
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);
|
||||
}
|
48
commands/utility/roleSelector.js
Normal file
48
commands/utility/roleSelector.js
Normal file
@ -0,0 +1,48 @@
|
||||
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,19 +35,9 @@ export async function execute(reaction, user) {
|
||||
// Fetch role from guild
|
||||
const guild = reaction.message.guild;
|
||||
const role = await guild.roles.fetch(rep.role);
|
||||
// Role not found
|
||||
if (role === null) {
|
||||
await user.send('Could not fetch role! Please contact server staff.');
|
||||
return;
|
||||
}
|
||||
if (role === null) return;
|
||||
|
||||
try {
|
||||
// Add role to user
|
||||
await guild.members.addRole({ role, user });
|
||||
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.');
|
||||
}
|
||||
// Add role to user
|
||||
await guild.members.addRole({ role, user });
|
||||
console.info(`[INFO] Added role with id '${role.id}' to user '${user.username}'.`);
|
||||
}
|
||||
|
@ -31,19 +31,9 @@ export async function execute(reaction, user) {
|
||||
// Fetch role from guild
|
||||
const guild = reaction.message.guild;
|
||||
const role = await guild.roles.fetch(rep.role);
|
||||
// Role not found
|
||||
if (role === null) {
|
||||
await user.send('Could not fetch role! Please contact server staff.');
|
||||
return;
|
||||
}
|
||||
if (role === null) return;
|
||||
|
||||
try {
|
||||
// Remove role from user
|
||||
await guild.members.removeRole({ role, user });
|
||||
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.');
|
||||
}
|
||||
// Add role to user
|
||||
await guild.members.removeRole({ role, user });
|
||||
console.info(`[INFO] Removed role with id '${role.id}' from user '${user.username}'.`);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user