Skip to content

Instantly share code, notes, and snippets.

@antishok
Created December 25, 2022 04:16
Show Gist options
  • Save antishok/bf9fc110acde454f8849b7d4804c3f70 to your computer and use it in GitHub Desktop.
Save antishok/bf9fc110acde454f8849b7d4804c3f70 to your computer and use it in GitHub Desktop.
discord command
const { ContextMenuCommandBuilder } = require('@discordjs/builders');
const { REST } = require('@discordjs/rest');
const { Routes, ApplicationCommandType } = require('discord-api-types/v9');
const config = require('./config/local.json');
const commands = [
new ContextMenuCommandBuilder()
.setName('Is user online?')
.setType(ApplicationCommandType.Message),
]
.map(command => command.toJSON());
const rest = new REST({ version: '9' }).setToken(config.discord.token);
rest.put(Routes.applicationGuildCommands(config.discord.botId, config.discord.guildId), { body: commands })
.then(() => console.log('Successfully registered application commands.'))
.catch(console.error);
if (interaction.targetType === 'MESSAGE' && interaction.commandName === 'Is user online?') {
console.log('INTERACTION user:', interaction.options?._hoistedOptions?.[0]?.message?.author);
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment