Context Commands Registering

I try in more than one way to record my commands, but they do not register my code:
const rest = new REST({ version: '10' }).setToken(token);

(async () => {
try {
console.log('Started refreshing application (/) commands.');

await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{
body: [
{
name: 'User Info',
type: ApplicationCommandType.User,
},
{
name: 'Timeout Member',
type: ApplicationCommandType.User,
}
]
}
);

console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();

client.on('interactionCreate', async interaction => {
if (!interaction.isUserContextMenuCommand()) return;

const targetUser = interaction.targetUser;
const member = interaction.guild.members.cache.get(targetUser.id);

if (interaction.commandName === 'User Info') {
const embed = new EmbedBuilder()
.setTitle(`${targetUser.username}'s Information`)
.setThumbnail(targetUser.displayAvatarURL({ dynamic: true }))
.addFields(
{ name: 'Username', value: targetUser.tag, inline: true },
{ name: 'Account Created', value: targetUser.createdAt.toDateString(), inline: true }
)
.setColor(0x00AE86);

await interaction.reply({ embeds: [embed], ephemeral: true });
}

if (interaction.commandName === 'Timeout Member') {
const options = {
'60 secs': 60 * 1000,
'5 mins': 5 * 60 * 1000,
'10 mins': 10 * 60 * 1000,
'1 hour': 60 * 60 * 1000,
'1 day': 24 * 60 * 60 * 1000,
'1 week': 7 * 24 * 60 * 60 * 1000,
};

const menu = Object.keys(options).map(label => ({
label,
value: label,
}));

const row = new MessageActionRow()
.addComponents(
new MessageSelectMenu()
.setCustomId('timeout_duration')
.setPlaceholder('Select timeout duration')
.addOptions(menu),
);

await interaction.reply({ content: 'Select a timeout duration:', components: [row], ephemeral: true });

const filter = i => i.customId === 'timeout_duration' && i.user.id === interaction.user.id;

const collector = interaction.channel.createMessageComponentCollector({ filter, time: 60000 });

collector.on('collect', async i => {
const durationLabel = i.values[0];
const duration = options[durationLabel];

try {
await member.timeout(duration);
await i.update({ content: `Member has been timeouted for ${durationLabel}.`, components: [], ephemeral: true });
} catch (err) {
await i.update({ content: 'Failed to timeout the member. Make sure I have the permissions.', components: [], ephemeral: true });
}
});
}
});
const rest = new REST({ version: '10' }).setToken(token);

(async () => {
try {
console.log('Started refreshing application (/) commands.');

await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{
body: [
{
name: 'User Info',
type: ApplicationCommandType.User,
},
{
name: 'Timeout Member',
type: ApplicationCommandType.User,
}
]
}
);

console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();

client.on('interactionCreate', async interaction => {
if (!interaction.isUserContextMenuCommand()) return;

const targetUser = interaction.targetUser;
const member = interaction.guild.members.cache.get(targetUser.id);

if (interaction.commandName === 'User Info') {
const embed = new EmbedBuilder()
.setTitle(`${targetUser.username}'s Information`)
.setThumbnail(targetUser.displayAvatarURL({ dynamic: true }))
.addFields(
{ name: 'Username', value: targetUser.tag, inline: true },
{ name: 'Account Created', value: targetUser.createdAt.toDateString(), inline: true }
)
.setColor(0x00AE86);

await interaction.reply({ embeds: [embed], ephemeral: true });
}

if (interaction.commandName === 'Timeout Member') {
const options = {
'60 secs': 60 * 1000,
'5 mins': 5 * 60 * 1000,
'10 mins': 10 * 60 * 1000,
'1 hour': 60 * 60 * 1000,
'1 day': 24 * 60 * 60 * 1000,
'1 week': 7 * 24 * 60 * 60 * 1000,
};

const menu = Object.keys(options).map(label => ({
label,
value: label,
}));

const row = new MessageActionRow()
.addComponents(
new MessageSelectMenu()
.setCustomId('timeout_duration')
.setPlaceholder('Select timeout duration')
.addOptions(menu),
);

await interaction.reply({ content: 'Select a timeout duration:', components: [row], ephemeral: true });

const filter = i => i.customId === 'timeout_duration' && i.user.id === interaction.user.id;

const collector = interaction.channel.createMessageComponentCollector({ filter, time: 60000 });

collector.on('collect', async i => {
const durationLabel = i.values[0];
const duration = options[durationLabel];

try {
await member.timeout(duration);
await i.update({ content: `Member has been timeouted for ${durationLabel}.`, components: [], ephemeral: true });
} catch (err) {
await i.update({ content: 'Failed to timeout the member. Make sure I have the permissions.', components: [], ephemeral: true });
}
});
}
});
any help plz?
No description
No description
13 Replies
d.js toolkit
d.js toolkit5w 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! - Marked as resolved by OP
TÆMBØ
TÆMBØ5w ago
What makes you think they aren't registered?
kuroiii
kuroiiiOP5w ago
this
No description
TÆMBØ
TÆMBØ5w ago
Reload Discord
kuroiii
kuroiiiOP5w ago
i do
TÆMBØ
TÆMBØ5w ago
As in, the app you're using to talk to me right now? And not your bot Because your first screenshot suggests they are registering if they're showing up in your integration settings
kuroiii
kuroiiiOP5w ago
I don't know, applications appear normally for me, but my application does not appear
kuroiii
kuroiiiOP5w ago
No description
TÆMBØ
TÆMBØ5w ago
Reload Discord once more and see. If they still end up not showing up, I suggest talking with folks in DDevs since this would be out control of d.js at this point
kuroiii
kuroiiiOP5w ago
Fine, thank u
Not_raman_fr
Not_raman_fr5w ago
ur using ApplicationCommandType.User, which makes user context commands like this
No description
No description
Not_raman_fr
Not_raman_fr5w ago
use ApplicationCommandType.Message as the type for msg context commands
No description
No description
kuroiii
kuroiiiOP5w ago
ok lmao ty
Want results from more Discord servers?
Add your server