intellisense not working

when i write inv. it doesnt follow up with any suggestions, like url for example
59 Replies
d.js toolkit
d.js toolkit•11mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Post the full error stack trace, not just the top part! - Show your code! - Explain what exactly your issue is. - Not a discord.js issue? Check out #useful-servers. - Issue solved? Press the button!
samurai jack
samurai jack•11mo ago
@Danial here yeah?
Danial
Danial•11mo ago
Yep
samurai jack
samurai jack•11mo ago
https://sourceb.in/UxJtRTCwdr alright heres the code. ignore the slash command builder, i was making a command and then just switched up and started trying to fix intellisense could you go to the console.log statement, and try to console.log(inv.url);? when i write inv. it doesnt follow up with any suggestions, like url for example discord.js@14.11.0, node v18.16.1 no error code sent issue: described above
Danial
Danial•11mo ago
What type does it show when you hover over interaction.channel?
samurai jack
samurai jack•11mo ago
which word specifically? interaction or channel
Danial
Danial•11mo ago
channel
samurai jack
samurai jack•11mo ago
(property)BaseInteraction<CacheType>.channel: TextBasedChannel | null TextBasedChannel no BaseInteraction is the type ? does it say smt different for you 🤔
Danial
Danial•11mo ago
Yep, shows the same for me, what's weird is when I do channel. it shows createInvite, and I let it autocomplete and it shows this but then when I hover over createInvite(), it shows any
samurai jack
samurai jack•11mo ago
yep same here i have all the autocomplete options for channel, but when i hover over createInvite() it shows any aswell
Danial
Danial•11mo ago
I've worked with JSDoc a bit but not much so I am not sure what's going on, it's been a while since I used JavaScript, I usually work with TypeScript, I'd recommend you look into TypeScript eventually as then it'd be a much nicer experience discord.js is very well typed, and will eventually be rewritten in TypeScript
samurai jack
samurai jack•11mo ago
oh ok np then thanks for the help though
Danial
Danial•11mo ago
Of course
samurai jack
samurai jack•11mo ago
for now i want to stay in JS ngl, so idk if ill be switching to typescript is there a way to get other people in here? simply because all the tutorials im seeing are in JS
Danial
Danial•11mo ago
This channel's public but as no one has interacted with it, it only shows us in the members list
samurai jack
samurai jack•11mo ago
👌 appreciate the help thanks
Danial
Danial•11mo ago
You shouldn't rely on tutorials, they also get oudated very soon, there's amazing documentation that can help you come up with things on your own
samurai jack
samurai jack•11mo ago
oh yeah im using the djs docs for my main source of learning
Danial
Danial•11mo ago
Awesome
samurai jack
samurai jack•11mo ago
uh
async execute(interaction) {
/** @type {Invite} */
const inv = await interaction.channel.createInvite()

console.log(inv.);
},
async execute(interaction) {
/** @type {Invite} */
const inv = await interaction.channel.createInvite()

console.log(inv.);
},
adding /** @type {Invite} */ directly above the inv variable made the intellisense work for it am i gonna have to do that for every single variable if i want intellisense to work?
Unknown User
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
samurai jack
samurai jack•11mo ago
yeah i already have that, i showed it in my code which i sent in a sourcebin above
Unknown User
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
samurai jack
samurai jack•11mo ago
problem is that even after adding that intellisebsewasn’t working
Unknown User
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
samurai jack
samurai jack•11mo ago
oh can you not see message history?
Unknown User
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
samurai jack
samurai jack•11mo ago
uh is it fine if i send it later? i’m on my phone rn lol
Unknown User
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
samurai jack
samurai jack•11mo ago
cool thanks
Unknown User
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
samurai jack
samurai jack•11mo ago
yeah someone else also recommended ts just didn’t want to switch so early since i’m still learning, using the official guide and djs docs seems like TS would be easier to use though
Unknown User
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
samurai jack
samurai jack•11mo ago
oh despairge just need to get some sort of intellisense working since i’m a beginner and it’s hard to experiment without knowing all the different methods and properties of a type 🗿 it works in index.js just not in the execute function there
Unknown User
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
samurai jack
samurai jack•11mo ago
waitwhathttps://sourceb.in/tnszO60rO4 here is the code, i wrote some comments to explain teh problem. also heres a reference to something i was told by another person in #djs-help-v14 : https://discord.com/channels/222078108977594368/824411059443204127/1132130195332136981
Unknown User
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
samurai jack
samurai jack•11mo ago
👌
Unknown User
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
samurai jack
samurai jack•11mo ago
yhh it is cuz the console.log(inv.url); works it outputs a url
Unknown User
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
samurai jack
samurai jack•11mo ago
wait so if its not a channel where an invite can be created on, the intellisense wont work? cuz it wont recognise it ?
Unknown User
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
samurai jack
samurai jack•11mo ago
oh i see so to conclude i cant get intellisense inside subdirectories unless i use jsDOC comments for each individual variable, or unless i use typescript ?
Unknown User
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
samurai jack
samurai jack•11mo ago
yeahh, i am pretty new to this its only been like a week so i havent memorised what everything returns will look into that though so that coding is easier anyway thanks for the help appreciate catthumbshup wait one more question does that mean what i was told here https://discord.com/channels/222078108977594368/824411059443204127/1132130195332136981 is wrong?
Unknown User
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
samurai jack
samurai jack•11mo ago
ohh i see thank you
Unknown User
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
samurai jack
samurai jack•11mo ago
hmmmm
async execute(interaction) {

const allowedChannels = [ChannelType.GuildText];

if (allowedChannels.includes(interaction.channel.type))
{
const inv = await interaction.channel.createInvite();
interaction.reply(inv.url);
}
else return;


},
async execute(interaction) {

const allowedChannels = [ChannelType.GuildText];

if (allowedChannels.includes(interaction.channel.type))
{
const inv = await interaction.channel.createInvite();
interaction.reply(inv.url);
}
else return;


},
i used this if statement to narrow it down more but the autocomplete still didnt show 🤔 ill try diff methods or maybe just move to typescript despairge tried both of those, but it didnt help the intellisense for (inv.url) it is what it is tho ill just work without the intellisense thanks tho
Unknown User
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
samurai jack
samurai jack•11mo ago
one sec seems like i used inCachedGuild() wrong
const { SlashCommandBuilder, PermissionFlagsBits, ChatInputCommandInteraction, PermissionOverwriteManager } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('lockdown')
.setDescription('Lockdown the selected channel')
.addChannelOption(option => option.setName('channel').setDescription('Channel to lockdown').setRequired(true))
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers)
.setDMPermission(false),

/**
* @param {ChatInputCommandInteraction<'cached'>} interaction
*
*/

async execute(interaction) {
const channel = interaction.options.getChannel('channel');

if (!interaction.inCachedGuild()) return;

const inv = await channel.createInvite();
await console.log(inv.url);

const everyoneRole = interaction.guild.roles.everyone;

await channel.permissionOverwrites.create(everyoneRole, { SendMessages: false });

await interaction.reply(`${channel} has been locked.`);
},
};
const { SlashCommandBuilder, PermissionFlagsBits, ChatInputCommandInteraction, PermissionOverwriteManager } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('lockdown')
.setDescription('Lockdown the selected channel')
.addChannelOption(option => option.setName('channel').setDescription('Channel to lockdown').setRequired(true))
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers)
.setDMPermission(false),

/**
* @param {ChatInputCommandInteraction<'cached'>} interaction
*
*/

async execute(interaction) {
const channel = interaction.options.getChannel('channel');

if (!interaction.inCachedGuild()) return;

const inv = await channel.createInvite();
await console.log(inv.url);

const everyoneRole = interaction.guild.roles.everyone;

await channel.permissionOverwrites.create(everyoneRole, { SendMessages: false });

await interaction.reply(`${channel} has been locked.`);
},
};
that is how you use it right? let me try restart my VSC
Unknown User
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
samurai jack
samurai jack•11mo ago
¯\_(ツ)_/¯ oh i changed it from my previous code apologies i should have clarified that
Unknown User
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs•11mo ago
samurai jack
samurai jack•11mo ago
oh yeah i had that code before, the ChannelType.GuildText then i removed it let me try it all together in one go
Unknown User
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
samurai jack
samurai jack•11mo ago
const channel = interaction.options.getChannel('channel', [ChannelType.GuildText]);
const channel = interaction.options.getChannel('channel', [ChannelType.GuildText]);
im assuming this is how its done
const channel = interaction.options.getChannel('channel', [ChannelType.GuildText]);

if (!interaction.inCachedGuild()) return;

const inv = await channel.createInvite();
const channel = interaction.options.getChannel('channel', [ChannelType.GuildText]);

if (!interaction.inCachedGuild()) return;

const inv = await channel.createInvite();
I have this now but it still shows 'any' when i hover over monkahmm updating my code to this it shows TextChannel and now the intellisense works for inv wow thanks a lot to everyone who helped genuinely really appreciate pepeok dont want to close this thread JUST yet alright so theres a few more questions i have firstly this has fixed my problem, and autocomplete/intellisense now shows up for the inv variable. - will intellisense now show up for any variable that i create, without having to specifiy the type in a jsDOC comment? secondly - youve shown me some code which solves my problem, but could you please explain WHY it fixes the problem it still works even after changing some code, e.g changing @param {ChatInputCommandInteraction<'cached'>} interaction to @param {ChatInputCommandInteraction} interaction, or simply just deleting the if (!interaction.inCachedGuild()) return;. im guessing i can just replace that with setDMPermission(false) im assuming that specifying the channel type with [ChannelType.GuildText] is the most important part thirdly is it simply because it narrows down the channel? - idrk how to word this but im not sure how to implement this same code in all my different commands, but i would definitely like to use this method to enable intellisense and autocomplete in all my sub directories. if there is one general way that i can do it for any type of variable then please let me know sorry if this seems like a lot of questions but this seems like the only place i can get help from people who can explain rather than just reading docs ohhh i see interesting i might do that in the near future thanks for all the pepeok