How to make slash commands work globally (in other servers and in dms where bot is not presentt

What do I do in my code to make it work? I have tried everything but the slash command does not work no matter what I do. I am using instaloader that is using a python script (isnt in the JS code, the js code only handles command).
27 Replies
d.js toolkit
d.js toolkit2mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
฀
OP2mo ago
Here is the code, what do i do to make Slash commands work globally
฀
OP2mo ago
i have tried what i could do,but it doesnt workj
Amgelo
Amgelo2mo ago
that problem has to do with how you deploy your commands not how you handle them so the issue is within your python script ask in the support for that library or whatever you're using this isn't djs related
฀
OP2mo ago
No no im askin how ot make the slash command work in dms and other servers, like for app.commands
Amgelo
Amgelo2mo ago
same answer
฀
OP2mo ago
How tho? because the script doesnt have anythin to do with the discord.js?
import sys
import instaloader

# Get Instagram URL passed from the Node.js script
url = sys.argv[1]

# Initialize Instaloader
L = instaloader.Instaloader()

# Extract post from URL
try:
# Load the post using the URL
post = instaloader.Post.from_shortcode(L.context, url.split("/")[-2])

# Check if the post is a video
if post.is_video:
print(post.video_url) # This will print the video URL
else:
print("No video found for this post.")
except Exception as e:
print(f"Error: {e}")
import sys
import instaloader

# Get Instagram URL passed from the Node.js script
url = sys.argv[1]

# Initialize Instaloader
L = instaloader.Instaloader()

# Extract post from URL
try:
# Load the post using the URL
post = instaloader.Post.from_shortcode(L.context, url.split("/")[-2])

# Check if the post is a video
if post.is_video:
print(post.video_url) # This will print the video URL
else:
print("No video found for this post.")
except Exception as e:
print(f"Error: {e}")
all it does is grabs the url which is given by the bot.js script please check only takes the url
Amgelo
Amgelo2mo ago
you said that you used instaloader
฀
OP2mo ago
Yeah thats for the python script, i was jus tellin what the program does what im askin help for is how to make slash commands work globally
Amgelo
Amgelo2mo ago
I have no idea what that is, I assumed that was for loading your commands
฀
OP2mo ago
in dms, other servers
Retro
Retro2mo ago
how are you loading your commands?
Amgelo
Amgelo2mo ago
how are you deploying your commands then
฀
OP2mo ago
try { // Register the slash command globally await client.application.commands.create( new SlashCommandBuilder() .setName('video') .setDescription('Get the video from an Instagram or TikTok post') .addStringOption(option => option.setName('url') .setDescription('The URL of the Instagram or TikTok post') .setRequired(true) ) );
𝑨𝒃𝒔𝒐𝒍𝒖𝒕𝒆 𝑪𝒂𝒓𝒏𝒂𝒈𝒆
Discord Developer Portal
Discord Developer Portal — API Docs for Bots and Developers
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
฀
OP2mo ago
yes i have those settings set on the bot on the discord developer portal
Retro
Retro2mo ago
its not enough to set them on discord developer protal. you need to set them when deploying ur commands
d.js docs
d.js docs2mo ago
:method: SlashCommandBuilder#setIntegrationTypes() @1.9.0 Sets the integration types of this command.
𝑨𝒃𝒔𝒐𝒍𝒖𝒕𝒆 𝑪𝒂𝒓𝒏𝒂𝒈𝒆
have u done the other things like the interaction endpoint?
Amgelo
Amgelo2mo ago
the api endpoint is called by djs in his code
฀
OP2mo ago
hm
Amgelo
Amgelo2mo ago
the problem is with his data as Retro said
฀
OP2mo ago
.setContexts([0, 1]) // 0 = Guild, 1 = BotDM // Allow the slash command to work in both guilds and DMs .setIntegrationTypes([0,1]) // Enable integration as a slash command globally is this how you do it? @Retro
Retro
Retro2mo ago
Check the url of the docs But yes that is how you do it but use enums that discord.js exports instead of magic numbers Also the maximum for context is array of size 3. Guild, dm and guild your bot has not been invited to
d.js docs
d.js docs2mo ago
:discord: Application Commands - Contexts Commands have two sets of contexts on the application command object that let you to configure when and where it can be used: read more
฀
OP2mo ago
thank you sir, it worked thank you @Retro @Ame @Abs oops @𝑨𝒃𝒔𝒐𝒍𝒖𝒕𝒆 𝑪𝒂𝒓𝒏𝒂𝒈𝒆

Did you find this page helpful?