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 toolkit4w 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
RUN
RUNOP4w ago
Here is the code, what do i do to make Slash commands work globally
RUN
RUNOP4w ago
i have tried what i could do,but it doesnt workj
Amgelo
Amgelo4w 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
RUN
RUNOP4w ago
No no im askin how ot make the slash command work in dms and other servers, like for app.commands
Amgelo
Amgelo4w ago
same answer
RUN
RUNOP4w 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
Amgelo4w ago
you said that you used instaloader
RUN
RUNOP4w 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
Amgelo4w ago
I have no idea what that is, I assumed that was for loading your commands
RUN
RUNOP4w ago
in dms, other servers
Retro
Retro4w ago
how are you loading your commands?
Amgelo
Amgelo4w ago
how are you deploying your commands then
RUN
RUNOP4w 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.
RUN
RUNOP4w ago
yes i have those settings set on the bot on the discord developer portal
Retro
Retro4w 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 docs4w 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
Amgelo4w ago
the api endpoint is called by djs in his code
RUN
RUNOP4w ago
hm
Amgelo
Amgelo4w ago
the problem is with his data as Retro said
RUN
RUNOP4w 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
Retro4w 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 docs4w 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
RUN
RUNOP4w ago
thank you sir, it worked thank you @Retro @Ame @Abs oops @𝑨𝒃𝒔𝒐𝒍𝒖𝒕𝒆 𝑪𝒂𝒓𝒏𝒂𝒈𝒆
Want results from more Discord servers?
Add your server