Xirez
DIAdiscord.js - Imagine an app
•Created by Xirez on 9/25/2023 in #djs-questions
Reaction on message based logic.
Hello!
I'm new to discord js, and i'm lost on what i "need".
Would love some guidance/links to a guid/docs that can help me.
So what i have today is a /apply command, you fill in a modal, and the bot will create an embed to admins for review. Today if a user is accepted, admins manually give them a role, if not they will right-click and delete the embed.
I would like to add the abillity for admins to react with ✅ to accept a user and give that user a role, and the bot should move the embed to "accepted chat". And if an admin reacts with ❎ the embed should simply be deleted.
How can i make this, and what is it i need to study?
6 replies
DIAdiscord.js - Imagine an app
•Created by Xirez on 9/24/2023 in #djs-questions
Modal submit, 2d time, crashes app
const { SlashCommandBuilder, ActionRowBuilder, Events, ModalBuilder, TextInputBuilder, TextInputStyle, InteractionType } = require('discord.js');
const db = require('../../models');
const Customer = db.customer;
const config = require('../../Configs/config.js');
module.exports = {
data: {
name: "register",
description: "Register as a customer or supplier.",
dm_permissions: "0",
},
async execute(interaction, client) {
const modal = new ModalBuilder()
.setCustomId('registerModal')
.setTitle('Register as a Customer & Supplier!');
const characterName = new TextInputBuilder()
.setCustomId('characterName')
.setLabel("What's your in-game character name?")
.setPlaceholder('Enter in-game character name')
.setStyle(TextInputStyle.Short);
const guildName = new TextInputBuilder()
.setCustomId('guildName')
.setLabel("What's your in-game guild name?")
.setPlaceholder('Enter in-game guild name')
.setStyle(TextInputStyle.Short);
const customerType = new TextInputBuilder()
.setCustomId('customerType')
.setLabel("What role do you wish to fulfill?")
.setPlaceholder('Supplier / Buyer / Both')
.setStyle(TextInputStyle.Short)
.setRequired(true);
const comment = new TextInputBuilder()
.setCustomId('comment')
.setLabel("Do you want to add something else?")
.setStyle(TextInputStyle.Paragraph)
.setRequired(false);
const characterActionRow = new ActionRowBuilder().addComponents(characterName);
const guildActionRow = new ActionRowBuilder().addComponents(guildName);
const customerActionRow = new ActionRowBuilder().addComponents(customerType);
const commentActionRow = new ActionRowBuilder().addComponents(comment);
modal.addComponents(characterActionRow, guildActionRow, customerActionRow, commentActionRow);
await interaction.showModal(modal)
client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isModalSubmit()) return;
if (interaction.customId === 'registerModal') {
const guild = await interaction.client.guilds.fetch(config.GUILD_ID);
const channel = await guild.channels.fetch(config[`REGISTER_FEED`]);
const customer = await Customer.findOne({ where: { discordId: interaction.user.id } });
if (!customer) {
await Customer.create({
discordName: interaction.user.tag,
discordId: interaction.user.id,
gameName: interaction.fields.getTextInputValue('characterName'),
gameGuild: interaction.fields.getTextInputValue('guildName'),
userType: interaction.fields.getTextInputValue('customerType'),
comment: interaction.fields.getTextInputValue('comment'),
});
await interaction.reply({ content: 'Your submission was received successfully!', ephemeral: true});
await channel.send({ content: `<@${interaction.user.id}> just registered!` });
} else {
await interaction.deferReply({ content: 'You are already registered!', ephemeral: true});
}
}
});
}
}
const { SlashCommandBuilder, ActionRowBuilder, Events, ModalBuilder, TextInputBuilder, TextInputStyle, InteractionType } = require('discord.js');
const db = require('../../models');
const Customer = db.customer;
const config = require('../../Configs/config.js');
module.exports = {
data: {
name: "register",
description: "Register as a customer or supplier.",
dm_permissions: "0",
},
async execute(interaction, client) {
const modal = new ModalBuilder()
.setCustomId('registerModal')
.setTitle('Register as a Customer & Supplier!');
const characterName = new TextInputBuilder()
.setCustomId('characterName')
.setLabel("What's your in-game character name?")
.setPlaceholder('Enter in-game character name')
.setStyle(TextInputStyle.Short);
const guildName = new TextInputBuilder()
.setCustomId('guildName')
.setLabel("What's your in-game guild name?")
.setPlaceholder('Enter in-game guild name')
.setStyle(TextInputStyle.Short);
const customerType = new TextInputBuilder()
.setCustomId('customerType')
.setLabel("What role do you wish to fulfill?")
.setPlaceholder('Supplier / Buyer / Both')
.setStyle(TextInputStyle.Short)
.setRequired(true);
const comment = new TextInputBuilder()
.setCustomId('comment')
.setLabel("Do you want to add something else?")
.setStyle(TextInputStyle.Paragraph)
.setRequired(false);
const characterActionRow = new ActionRowBuilder().addComponents(characterName);
const guildActionRow = new ActionRowBuilder().addComponents(guildName);
const customerActionRow = new ActionRowBuilder().addComponents(customerType);
const commentActionRow = new ActionRowBuilder().addComponents(comment);
modal.addComponents(characterActionRow, guildActionRow, customerActionRow, commentActionRow);
await interaction.showModal(modal)
client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isModalSubmit()) return;
if (interaction.customId === 'registerModal') {
const guild = await interaction.client.guilds.fetch(config.GUILD_ID);
const channel = await guild.channels.fetch(config[`REGISTER_FEED`]);
const customer = await Customer.findOne({ where: { discordId: interaction.user.id } });
if (!customer) {
await Customer.create({
discordName: interaction.user.tag,
discordId: interaction.user.id,
gameName: interaction.fields.getTextInputValue('characterName'),
gameGuild: interaction.fields.getTextInputValue('guildName'),
userType: interaction.fields.getTextInputValue('customerType'),
comment: interaction.fields.getTextInputValue('comment'),
});
await interaction.reply({ content: 'Your submission was received successfully!', ephemeral: true});
await channel.send({ content: `<@${interaction.user.id}> just registered!` });
} else {
await interaction.deferReply({ content: 'You are already registered!', ephemeral: true});
}
}
});
}
}
rawError: { message: 'Unknown interaction', code: 10062 }
rawError: { message: 'Unknown interaction', code: 10062 }
10 replies