Reputation: 75
I've created a simple slash command. It works on the only guild. before that, I was using v12. Now I wanna switch to v13. Now how can I make these global slash commands?
Code
client.on ("ready", () => {
console.log(`${client.user.tag} Has logged in`)
client.user.setActivity(`/help | ${client.user.username}`, { type: "PLAYING" })
const guildId = "914573324485541928"
const guild = client.guilds.cache.get(guildId)
let commands
if (guild) {
commands = guild.commands
} else {
commands = client.application.commands
}
commands.create({
name: 'ping',
description: 'Replies with pong'
})
commands.create({
name: 'truth',
description: 'Replies with truth'
})
});
client.on('interactionCreate', async (interaction) => {
if(!interaction.isCommand()){
return
}
const { commandName, options } = interaction
if (commandName === 'ping'){
interaction.reply({
content: 'pong'
})
}
```
I'm new in v13 so please explain it simply :|
Upvotes: 0
Views: 6047
Reputation: 9041
Simply change the guild
declaration. Your code checks if guild
is truthy, and uses the guild if it is. Otherwise, it will use global commands
const guild = null
// any falsy value is fine (undefined, false, 0, '', etc.)
Upvotes: 2