Context Commands Registering
I try in more than one way to record my commands, but they do not register
my code:
any help plz?
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?

