![]() Now that I have a class name, I can just look it up in the reference! The guide doesn’t mention a way of providing a GuildResolvable, but I can see from Discord.js’s lovely type annotations that appCmd.permissions is an ApplicationCommandPermissionsManager. This is because I don’t want my bot to be restricted to a single Discord server/guild, I want it to run in multiple servers. Notice that I’m getting my command from client.application, not (''), because it is a global command, not a guild command. Secondly, even after fetching the right command and adding permissions to it, it would fail with the following error: Permissions for global commands may only be fetched or modified by providing a GuildResolvable or from a guild's application command manager. Then you can just loop through all the commands and look for the command with the right command name (in my case, reset-counter). commands.fetch() without any arguments and it’ll return a JavaScript collection of all the commands, indexed by ID. For that, it turns out you can just call. Firstly, there’s no clear way to get the ID of the slash command you want to edit permissions for. Simple enough, right? Except this doesn’t work. You fetch the application details, you find the command you want, and you add the permissions you want to it. name = `reset-counter` is the name of the slash commandĬonst appCmd = await ( '') There is a page on slash command permissions, which looked like exactly what I wanted, and which told me to effectively do this 1: // `client` is a Discord.js Client object Using the guide, I was able to create the command that I wanted, minus the role thing. The main website is basically a reference page, and there’s a guide website linked in the header. only allow moderators to ban people, etc), so I was surprised that the documentation on this was a bit lacking. Now I imagine this situation comes up often (eg. Since I like JavaScript, I found a JavaScript library to help me out with this, discord.js, and got started.Īs part of this, the bot had a slash command that was supposed to be accessible only to people with a certain role in the server. So I was recently making a very simple Discord bot as a joke. ![]() I don’t think I’ll write another article about how to fix this, but here is a diff of me going from the contents of this article to doing things “the right way”. The Discord.js API has been updated and these steps do not work any more, and they have provided a much nicer API (and one that’s actually documented!) since. UPDATE (June 28, 2022): Most of this article is now outdated. Prose Home Portfolio Contact Jan 16 2022, 1:24 AM Make your Discord.js bot's global slash commands accessible only to certain roles Secrets that the documentation won't tell you (not sure why though).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |