Discord.js Slash Command permissions - discord.js

I want to create Slash Command Permissions on my Bot, so that the Command is grey for those who don´t have permissions for the Command, but I don´t find anything usefull for this problem.
I using the Command-Handler from discordjs.guide
This is my Code

Sorry, I may not help you, but I do not know the exact answer to your question, but I suggest you to use Worm Off Keys, using it is very easy, You can set permission in the command file by using permissions: ['ADMINISTRATOR'], in the command properties, and you can get/reply to the user in easy way:
const user = message : message ? interaction;
user.reply({ content: "properties test" })
This is just an example.

Related

Get GuildMember by UserId in discord.js v13 Slash Command

I've searched a lot of data so far, but I can't find any code that works. Can you tell me the code you get?
This is how I register Slash Command.
client.api.applications(client.user.id).guilds(guild).commands.post({
data: {
name: command.name,
description: command.description,
options: command.options
}
});
I'm Korean, so I wrote a translator.
To get the GuidMember details of the user by the user's id, you would first have to fetch the guild id, then you can use client.guilds.cache.get(guildid).members.cache.get(userid). But since you are doing this in a slash command, you would receive an Interaction object when the user uses the slash command, so then you can just use interaction.guild.members.cache.get(userid). If you want to get the GuildMember details of the user who ran the slash command, then you can just use const guildmember = interaction.member

Discord.js - Getting additional Text from Slash Command

When writing a Discord.js Slash Command, is it possible to get the text that was entered "outside" of the defined options?
Let's say I have the following SlashCommand defined:
new SlashCommandBuilder()
.setName('slashtest')
.addStringOption(option => option.setName('name').setDescription('Test Option').setRequired(true))
.addStringOption(option => option.setName('text').setDescription('Second Option').setRequired(true)),
In this example I would like to get the text "Even more Stuff"
According to the discord.js documentation and the discord developer documentation, you can only get user input from the command options in the discord slash command 'handler' (the menu that pops up when you enter '/').
From my past experience of using slash commands, I don't believe it's possible to retrieve user input outside of options. I guess you could create more options for more specific user input.

Slash commands only work on one Discord server? (discord.js v13)

I noticed that slash commands only work on one Discord server: bot.guilds.cache.get(<GUILD_ID>).commands.set(command.name, command).
Is there really no way to make the commands work right away on those servers where the bot already exists? Do I have to add IDs separately? I tried bot.guilds.cache.map(guild => guild.id).commands.set(command.name, command), but it gives an error TypeError: Cannot read properties of undefined (reading 'set').
Use Client#application to make a global command (works on all servers the bot is in with application.commands scope).
Use Guild#commands for guild specific commands
bot.on("ready", () => {
bot.application.commands.set([
// Global command data
])
})
And for guild specific command:
bot.guilds.cache.get("THE_GUILD_ID").commands.set(
[
// Guild command data
]
)

Specific command in chosen channel only

I would like to make a specific command (!verify) in the chosen channel.
Q: What does it mean?
A: The answer is simple. I would like users to be able to write only this command to this channel and nothing else.
Library: Discord.js
You can do the following:
if (message.channel.id === 'id-of-allowed-channel') {
//rest of your code
}
This way, the command is only executed if the id of the channel where the message is sent in equals the id of the channel that you want the command to work in :)
But I need to be able to write only a certain command in this channel. I already know how to select a specific channel, it's just the command.

How to only allow a command to be ran by the bot owner (me)

Im working on my discord bot and I have a stop command. The only problem with it is that it can be ran by anyone. I looked at other posts but didn't understand it. Thanks
Simple, just put this in the beginning of the scope where the command is executed:
if (message.author.id != "<your id here>") return;

Resources