Button interaction how to get the guild cache from former command

const { EmbedBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder } = require('discord.js')
module.exports = {
data: {
name: 'rbcy'
},
async execute(interaction, client) {
const claim = new EmbedBuilder()
.setDescription(`Creating a new category... This may take a while!`)
.setColor('Yellow');
const cls = new ButtonBuilder()
.setCustomId('rbcy')
.setLabel('Replace')
.setStyle(ButtonStyle.Success)
.setDisabled(true);
const clsr = new ButtonBuilder()
.setCustomId('rbcn')
.setLabel('No')
.setStyle(ButtonStyle.Danger)
.setDisabled(true);
await interaction.message.edit(
{
embeds: [claim],
components: [
new ActionRowBuilder().addComponents(cls, clsr),
],
})
.catch(err => console.log(err));

await category.delete()
.catch(() => { });

const channel = await interaction.guild.channels.create({
name: "ModMail",
type: ChannelType.GuildCategory,
permissionOverwrites: [
{
id: guild.roles.everyone,
deny: [PermissionFlagsBits.ViewChannel],
},
]
}).catch(console.log);

let roles = [];

if (config.Modmail.MAIL_MANAGER_ROLES) {
config.Modmail.MAIL_MANAGER_ROLES.forEach(async (role) => {
const roleFetched = interaction.guild.roles.cache.get(role);
if (!roleFetched) return roles.push('[INVALID ROLE]');

roles.push(roleFetched);

await channel.permissionOverwrites.create(roleFetched.id, {
SendMessages: true,
ViewChannel: true,
AttachFiles: true
})
});
} else {
roles.push("No roles were added to config.js file");
}

interaction.editReply(
{
embeds: [
new EmbedBuilder()
.setDescription(`Done, successfully created a mail category named **ModMail**.`)
.addFields(
{ name: "Roles", value: roles.join(', ') + "." }
)
.setFooter(
{
text: "WARN: Please check the roles in the category channel, errors could happen in anytime."
}
)
.setColor('Green')
]
}
).catch(() => { });

return collectorREPLACE_CHANNEL.stop();
}
}
const { EmbedBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder } = require('discord.js')
module.exports = {
data: {
name: 'rbcy'
},
async execute(interaction, client) {
const claim = new EmbedBuilder()
.setDescription(`Creating a new category... This may take a while!`)
.setColor('Yellow');
const cls = new ButtonBuilder()
.setCustomId('rbcy')
.setLabel('Replace')
.setStyle(ButtonStyle.Success)
.setDisabled(true);
const clsr = new ButtonBuilder()
.setCustomId('rbcn')
.setLabel('No')
.setStyle(ButtonStyle.Danger)
.setDisabled(true);
await interaction.message.edit(
{
embeds: [claim],
components: [
new ActionRowBuilder().addComponents(cls, clsr),
],
})
.catch(err => console.log(err));

await category.delete()
.catch(() => { });

const channel = await interaction.guild.channels.create({
name: "ModMail",
type: ChannelType.GuildCategory,
permissionOverwrites: [
{
id: guild.roles.everyone,
deny: [PermissionFlagsBits.ViewChannel],
},
]
}).catch(console.log);

let roles = [];

if (config.Modmail.MAIL_MANAGER_ROLES) {
config.Modmail.MAIL_MANAGER_ROLES.forEach(async (role) => {
const roleFetched = interaction.guild.roles.cache.get(role);
if (!roleFetched) return roles.push('[INVALID ROLE]');

roles.push(roleFetched);

await channel.permissionOverwrites.create(roleFetched.id, {
SendMessages: true,
ViewChannel: true,
AttachFiles: true
})
});
} else {
roles.push("No roles were added to config.js file");
}

interaction.editReply(
{
embeds: [
new EmbedBuilder()
.setDescription(`Done, successfully created a mail category named **ModMail**.`)
.addFields(
{ name: "Roles", value: roles.join(', ') + "." }
)
.setFooter(
{
text: "WARN: Please check the roles in the category channel, errors could happen in anytime."
}
)
.setColor('Green')
]
}
).catch(() => { });

return collectorREPLACE_CHANNEL.stop();
}
}
the category is fetched by former setup slash command how can i get it then using in button commnad interaciton
6 Replies
d.js toolkit
d.js toolkit2w ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
treble/luna
treble/luna2w ago
Pass the id in the customId of the button and splice it out
Unicorn.
Unicorn.OP2w ago
i mean categroy snowflower which was definied in slashcommand i need get it in button
treble/luna
treble/luna2w ago
yes so pass it in in the customid of the button
Eleonor
Eleonor6d ago
you can try interaction.message.interactionMetadata.interactedMessageId
treble/luna
treble/luna6d ago
thats the id of the message the button is on which is the same as interaction.message.id and is not what they are looking for

Did you find this page helpful?