how could roleat change with position(name of roleid) string change
const { roleMention , SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder, WebhookClient } = require('discord.js');
const { RoleID, webhookId, webhookToken } = require('../../config/plugins/promote.json');
const webhookClient = new WebhookClient({ id: webhookId, token: webhookToken });
module.exports = {
data: new SlashCommandBuilder()
.setName('promote')
.setDescription('Select a member and promote them.')
.addUserOption(option =>
option
.setName('target')
.setDescription('The member to promote')
.setRequired(true))
.addStringOption(option =>
option
.setName('position')
.setDescription('The position for pormoting')
.setRequired(true)
.addChoices(
{ name: 'Event Team', value: 'CC' },
{ name: 'Media Team', value: 'Media' },
{ name: 'Driver', value: 'Driver' },
{ name: 'Driver Trainee', value: 'Trainee' },
))
.setDefaultMemberPermissions(PermissionFlagsBits.ManageRoles)
.setDMPermission(false),
async execute(interaction) {
const member = interaction.options.getMember('target');
const avatarURL = member.user.displayAvatarURL({size:4096});
const userID = member.id;
const position = interaction.options.getString('position');
const success = new EmbedBuilder()
.setColor('#AC00FF')
.setThumbnail(avatarURL)
.setTitle(`Member Role Change`)
.setDescription(`**<@${userID}>** has promoted to **${RoleID.position}**`)
const error = new EmbedBuilder()
.setColor('Red')
.setTitle(`Error`)
.setDescription(`Commmand error`);
function CC() {
member.roles.add(RoleID.Devide1);
member.roles.add(RoleID.CC);
webhookClient.send({
embeds: [success.setImage('https://cdn.discordapp.com/attachments/929319867457347636/1103853149745332285/ZmT1EEV2.png')],
});
interaction.reply({ content: 'Success!', ephemeral: true });
}
function Driver() {
member.roles.add(RoleID.Driver);
member.roles.remove(RoleID.Trainee);
webhookClient.send({
embeds: [success],
});
interaction.reply({ content: 'Success!', ephemeral: true });
}
function Media() {
member.roles.add(RoleID.Devide1);
member.roles.add(RoleID.Media);
webhookClient.send({
embeds: [success],
});
interaction.reply({ content: 'Success!', ephemeral: true });
}
function Trainee() {
member.roles.add(RoleID.Devide2);
member.roles.add(RoleID.Trainee);
webhookClient.send({
embeds: [success.setDescription(`**<@${userID}>** joins Federal Transport VTC as **<@${roleat}>**`)],
});
interaction.reply({ content: 'Success!', ephemeral: true });
}
if (position == 'CC') {
CC();
}
else if (position == 'Media') {
Media();
}
else if (position == 'Driver') {
Driver();
}
else if (position == 'Trainee'){
Trainee();
}
else
{
interaction.reply(
{embed:[error],
});
return;
}
},
};
const { roleMention , SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder, WebhookClient } = require('discord.js');
const { RoleID, webhookId, webhookToken } = require('../../config/plugins/promote.json');
const webhookClient = new WebhookClient({ id: webhookId, token: webhookToken });
module.exports = {
data: new SlashCommandBuilder()
.setName('promote')
.setDescription('Select a member and promote them.')
.addUserOption(option =>
option
.setName('target')
.setDescription('The member to promote')
.setRequired(true))
.addStringOption(option =>
option
.setName('position')
.setDescription('The position for pormoting')
.setRequired(true)
.addChoices(
{ name: 'Event Team', value: 'CC' },
{ name: 'Media Team', value: 'Media' },
{ name: 'Driver', value: 'Driver' },
{ name: 'Driver Trainee', value: 'Trainee' },
))
.setDefaultMemberPermissions(PermissionFlagsBits.ManageRoles)
.setDMPermission(false),
async execute(interaction) {
const member = interaction.options.getMember('target');
const avatarURL = member.user.displayAvatarURL({size:4096});
const userID = member.id;
const position = interaction.options.getString('position');
const success = new EmbedBuilder()
.setColor('#AC00FF')
.setThumbnail(avatarURL)
.setTitle(`Member Role Change`)
.setDescription(`**<@${userID}>** has promoted to **${RoleID.position}**`)
const error = new EmbedBuilder()
.setColor('Red')
.setTitle(`Error`)
.setDescription(`Commmand error`);
function CC() {
member.roles.add(RoleID.Devide1);
member.roles.add(RoleID.CC);
webhookClient.send({
embeds: [success.setImage('https://cdn.discordapp.com/attachments/929319867457347636/1103853149745332285/ZmT1EEV2.png')],
});
interaction.reply({ content: 'Success!', ephemeral: true });
}
function Driver() {
member.roles.add(RoleID.Driver);
member.roles.remove(RoleID.Trainee);
webhookClient.send({
embeds: [success],
});
interaction.reply({ content: 'Success!', ephemeral: true });
}
function Media() {
member.roles.add(RoleID.Devide1);
member.roles.add(RoleID.Media);
webhookClient.send({
embeds: [success],
});
interaction.reply({ content: 'Success!', ephemeral: true });
}
function Trainee() {
member.roles.add(RoleID.Devide2);
member.roles.add(RoleID.Trainee);
webhookClient.send({
embeds: [success.setDescription(`**<@${userID}>** joins Federal Transport VTC as **<@${roleat}>**`)],
});
interaction.reply({ content: 'Success!', ephemeral: true });
}
if (position == 'CC') {
CC();
}
else if (position == 'Media') {
Media();
}
else if (position == 'Driver') {
Driver();
}
else if (position == 'Trainee'){
Trainee();
}
else
{
interaction.reply(
{embed:[error],
});
return;
}
},
};
2 Replies
• What's your exact discord.js
npm list discord.js
and node node -v
version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.roleat require string or it says undefined
it's the roleid(Snowflake) which used in embed to at the role
it changes with function such as cc - roleid.cc
media roleid.media
but it can't get the snowflake of the id just reply undefined
oh it's snowflake not string
🤦🏼♂️ my mistake
i means in cc function i need roleid.cc
in media function i need roleid.media
it need to change in same embed{success} but different mention role
const success = new EmbedBuilder()
.setColor('#AC00FF')
.setThumbnail(avatarURL)
.setTitle(`Member Role Change`)
.setDescription(`**<@${userID}>** has promoted to **${Roleid//the role need to at}**`)
const error = new EmbedBuilder()
.setColor('Red')
.setTitle(`Error`)
.setDescription(`Commmand error`);
const success = new EmbedBuilder()
.setColor('#AC00FF')
.setThumbnail(avatarURL)
.setTitle(`Member Role Change`)
.setDescription(`**<@${userID}>** has promoted to **${Roleid//the role need to at}**`)
const error = new EmbedBuilder()
.setColor('Red')
.setTitle(`Error`)
.setDescription(`Commmand error`);