Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

discord.js how to use subcommands

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

	if (interaction.commandName === 'info') {
		if (interaction.options.getSubcommand() === 'user') {
			const user = interaction.options.getUser('target');

			if (user) {
				await interaction.reply(`Username: ${user.username}
ID: ${user.id}`);
			} else {
				await interaction.reply(`Your username: ${interaction.user.username}
Your ID: ${interaction.user.id}`);
			}
		} else if (interaction.options.getSubcommand() === 'server') {
			await interaction.reply(`Server name: ${interaction.guild.name}
Total members: ${interaction.guild.memberCount}`);
		}
	}
});
Source by discordjs.guide #
 
PREVIOUS NEXT
Tagged: #subcommands
ADD COMMENT
Topic
Name
4+2 =