I cant use my anycommand

Even if I fix my internet connection problem I got this error
103 Replies
d.js toolkit
d.js toolkit•3y 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.
treble/luna
treble/luna•3y ago
then you either did not fix it or your code takes too long to execute
Mockir
MockirOP•3y ago
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Mockir
MockirOP•3y ago
Ill try now No it didnt fix
treble/luna
treble/luna•3y ago
then i dont know, might be your home network, might be your server network, but its not djs related it looks like
Duff
Duff•3y ago
First of all, messy code. Second, is the bot even registering the ping command? Log it when you run the command and check
treble/luna
treble/luna•3y ago
it is being ran, can be seen in the stacktrace
Mockir
MockirOP•3y ago
I started coding again all project I try change my interaction create part
!"Unkown
!"Unkown•3y ago
lines 15 do it like this !(code) not like this !interaction.type ==
treble/luna
treble/luna•3y ago
Or just !== ?
!"Unkown
!"Unkown•3y ago
yeah
Mockir
MockirOP•3y ago
const { InteractionType } = require("discord.js");
const { users } = require('../../lib/database.js')
module.exports = {
name: 'interactionCreate',
execute: async(interaction) => {
let client = interaction.client;
if (interaction.type == InteractionType.ApplicationCommand) {
if(interaction.user.bot) return;
const user = users(interaction.user.id)
try {
if(!user) return interaction.reply('Merhaba Dostum! Seninle ilk defa karşılaşıyoruz. O yüzden bu komutu kullanmadan önce sana bir "Merhaba" demek istedim. Umarım seninle çok güzel vakit geçirebiliriz.')
if(user.banned === true) return;
const command = client.slashcommands.get(interaction.commandName)
command.run(client, interaction)
} catch (e) {
console.error(e)
interaction.reply({content: "Komut çalıştırılırken bir sorunla karşılaşıldı! Lütfen tekrar deneyin.", ephemeral: true})
}
}
}}
const { InteractionType } = require("discord.js");
const { users } = require('../../lib/database.js')
module.exports = {
name: 'interactionCreate',
execute: async(interaction) => {
let client = interaction.client;
if (interaction.type == InteractionType.ApplicationCommand) {
if(interaction.user.bot) return;
const user = users(interaction.user.id)
try {
if(!user) return interaction.reply('Merhaba Dostum! Seninle ilk defa karşılaşıyoruz. O yüzden bu komutu kullanmadan önce sana bir "Merhaba" demek istedim. Umarım seninle çok güzel vakit geçirebiliriz.')
if(user.banned === true) return;
const command = client.slashcommands.get(interaction.commandName)
command.run(client, interaction)
} catch (e) {
console.error(e)
interaction.reply({content: "Komut çalıştırılırken bir sorunla karşılaşıldı! Lütfen tekrar deneyin.", ephemeral: true})
}
}
}}
Is it ok?
!"Unkown
!"Unkown•3y ago
no? or yes try it and see if the results satisfy u
Mockir
MockirOP•3y ago
Can I use editReply() after reply() ?
treble/luna
treble/luna•3y ago
Yes
Mockir
MockirOP•3y ago
Mockir
MockirOP•3y ago
thats my interactionCreate event But still I got this error
treble/luna
treble/luna•3y ago
can you try loggin client.ws.ping? Might maybe give you some clue
Mockir
MockirOP•3y ago
Ok I will try
Mockir
MockirOP•3y ago
Mockir
MockirOP•3y ago
1219 ms WTF?
treble/luna
treble/luna•3y ago
and there is your issue
!"Unkown
!"Unkown•3y ago
are u using windows 7?
Mockir
MockirOP•3y ago
Thats Virtual Device What is this btw? Client.ws.ping?
treble/luna
treble/luna•3y ago
your websocket latency
Mockir
MockirOP•3y ago
What could be causing the problem? and how can I fix it
treble/luna
treble/luna•3y ago
Switching hosts looks to be the only way Or do you happen to use a vpn or proxy
Mockir
MockirOP•3y ago
No I dont use
treble/luna
treble/luna•3y ago
Switch to a better host would be your best guess
Mockir
MockirOP•3y ago
Must be another way
treble/luna
treble/luna•3y ago
do you use anything else that's network intensive?
Mockir
MockirOP•3y ago
No I just use Visual Studio
treble/luna
treble/luna•3y ago
Welp, time to get a better host probably
KAVI
KAVI•3y ago
Just for further understanding. Websocket Latency is determined by the trip it takes for your bot to communicate with the discord gateway. Bad network = more trip time = more latency If the host is giving costant high latency performance... I don't see the reason to stick with it tbh
!"Unkown
!"Unkown•3y ago
and the distance between the host and the discord servers
KAVI
KAVI•3y ago
And that yeah. But even if the host is pretty far away, If the netwrork route is good. You can work with the ping. 300ms to SG is not bad. With some proper coding and handling it's barely noticeable.
Mockir
MockirOP•3y ago
I sometimes get 144ms but sometimes 1000+ ms Why ping is change...
treble/luna
treble/luna•3y ago
do you use a shared host
Mockir
MockirOP•3y ago
Probably yes
treble/luna
treble/luna•3y ago
There is your answer
Mockir
MockirOP•3y ago
I use host only
KAVI
KAVI•3y ago
Yeah... if shared, when the surrounding gets heated up with traffic, your area suffers To put it simply
treble/luna
treble/luna•3y ago
Anyhow, whether its shared or not, get a better host
KAVI
KAVI•3y ago
Or a host that has reasonable performance even when shared. It's the root cause that's why we're consistent about it
Mockir
MockirOP•3y ago
aahh I live in Turkey and we got a little economic problem and soo this host problem is very expensive is another country And I cant get a risk If after I get a host from USA and then if still I get this error Thats can be so bad for me
treble/luna
treble/luna•3y ago
i pay like 5€ a month for my hetzner server
Mockir
MockirOP•3y ago
Probably I paid same cost
KAVI
KAVI•3y ago
I pay nothing for my VPS, but with a risk I'm taking to use what I get to it's full potential OK so you changed the hosting service ? And the network is good without any latencies ? But the problem still persists ? Then the problem is your code mate.
Mockir
MockirOP•3y ago
- yes - yes - yes -
const { EmbedBuilder, PermissionsBitField } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");

module.exports = {
data: new SlashCommandBuilder()
.setName("ping")
.setDescription("Pong!"),
run: async (client, interaction) => {
console.log(client.ws.ping)
const sent = await interaction.reply({ content: 'Ping ölçülüyor...', fetchReply: true });
interaction.editReply(`Ping: ${sent.createdTimestamp - interaction.createdTimestamp}ms`);
}
};
const { EmbedBuilder, PermissionsBitField } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");

module.exports = {
data: new SlashCommandBuilder()
.setName("ping")
.setDescription("Pong!"),
run: async (client, interaction) => {
console.log(client.ws.ping)
const sent = await interaction.reply({ content: 'Ping ölçülüyor...', fetchReply: true });
interaction.editReply(`Ping: ${sent.createdTimestamp - interaction.createdTimestamp}ms`);
}
};
Mockir
MockirOP•3y ago
KAVI
KAVI•3y ago
That last line is wrong. You can only use editReply after an interaction is deferred. Use followUp instead. Or use the variable and do sent.edit()
Mockir
MockirOP•3y ago
Okey I will did it Luna said yes
Mockir
MockirOP•3y ago
Mockir
MockirOP•3y ago
const { EmbedBuilder, PermissionsBitField } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");

module.exports = {
data: new SlashCommandBuilder()
.setName("ping")
.setDescription("Pong!"),
run: async (client, interaction) => {
console.log(client.ws.ping)
const sent = await interaction.reply({ content: 'Ping ölçülüyor...', fetchReply: true });
sent.edit(`Ping: ${sent.createdTimestamp - interaction.createdTimestamp}ms`);
}
};
const { EmbedBuilder, PermissionsBitField } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");

module.exports = {
data: new SlashCommandBuilder()
.setName("ping")
.setDescription("Pong!"),
run: async (client, interaction) => {
console.log(client.ws.ping)
const sent = await interaction.reply({ content: 'Ping ölçülüyor...', fetchReply: true });
sent.edit(`Ping: ${sent.createdTimestamp - interaction.createdTimestamp}ms`);
}
};
KAVI
KAVI•3y ago
i guess something is increbily wrong in how you're handling the interactions. If the command is right then the next place is where you handle the interactionCreate event. If that's also correct then your event handler is the culprit
treble/luna
treble/luna•3y ago
if you switched to a different host, try logging the ping again and see
Mockir
MockirOP•3y ago
Websocket hb is now 144 and 150 it doesnt have Problem now Here is my interactionCreate event
const { InteractionType } = require("discord.js");
const { users } = require('../../lib/database.js')
module.exports = {
name: 'interactionCreate',
execute: async(interaction) => {
let client = interaction.client;
if (interaction.type === InteractionType.ApplicationCommand) {
if(interaction.user.bot) return;
const user = users(interaction.user.id)
if(!user) return interaction.reply('Merhaba Dostum! Seninle ilk defa karşılaşıyoruz. O yüzden bu komutu kullanmadan önce sana bir "Merhaba" demek istedim. Umarım seninle çok güzel vakit geçirebiliriz.')
if(user.banned === true) return;
const command = client.slashcommands.get(interaction.commandName)
command.run(client, interaction)
//Hata Ayıklama
process.on('uncaughtException', function (err) {
console.error('Uncaught Exception:', err.stack);
});
}
}}
const { InteractionType } = require("discord.js");
const { users } = require('../../lib/database.js')
module.exports = {
name: 'interactionCreate',
execute: async(interaction) => {
let client = interaction.client;
if (interaction.type === InteractionType.ApplicationCommand) {
if(interaction.user.bot) return;
const user = users(interaction.user.id)
if(!user) return interaction.reply('Merhaba Dostum! Seninle ilk defa karşılaşıyoruz. O yüzden bu komutu kullanmadan önce sana bir "Merhaba" demek istedim. Umarım seninle çok güzel vakit geçirebiliriz.')
if(user.banned === true) return;
const command = client.slashcommands.get(interaction.commandName)
command.run(client, interaction)
//Hata Ayıklama
process.on('uncaughtException', function (err) {
console.error('Uncaught Exception:', err.stack);
});
}
}}
And my event-handler
//event-handler
readdirSync('./src/events').forEach(async file => {
const event = await require(`./src/events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
})
//event-handler
readdirSync('./src/events').forEach(async file => {
const event = await require(`./src/events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
})
Bro can u look?
KAVI
KAVI•3y ago
The handler is fine I guess. As for the interaction handler. I'm curious as to why you're checking the interaction type When type guards exist And also curious why you're using a process error handler inside the interaction handler While you can handle that in the main index file for global code coverage
Mockir
MockirOP•3y ago
Before I use inside of index.js Oh ok I will change it again
KAVI
KAVI•3y ago
Also uncaughtException doesn't catch unhandledRejection The latter mostly happens when discord API errors happen
Mockir
MockirOP•3y ago
Oh wait I add also
KAVI
KAVI•3y ago
Yeah please remove that if statement and use normal type guards. For example interaction.isButton() exists to handle button interactions
Mockir
MockirOP•3y ago
Okeyy
process.on("unhandledRejection", e => {
console.log(e)
})
process.on("uncaughtException", e => {
console.log(e)
})
process.on("uncaughtExceptionMonitor", e => {
console.log(e)
})
process.on("unhandledRejection", e => {
console.log(e)
})
process.on("uncaughtException", e => {
console.log(e)
})
process.on("uncaughtExceptionMonitor", e => {
console.log(e)
})
KAVI
KAVI•3y ago
This is fine.
Mockir
MockirOP•3y ago
Is it ok for get error? Oh oke
KAVI
KAVI•3y ago
Yep that's enough to cover most of the errors. But sometimes you still need a try catch block / .catch() to catch some errors that escape https://old.discordjs.dev/#/docs/discord.js/main/class/BaseInteraction if you're lost Slash commands are isChatInputCommand()
Mockir
MockirOP•3y ago
I try but I got same error
Mockir
MockirOP•3y ago
Mockir
MockirOP•3y ago
const { EmbedBuilder, PermissionsBitField } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");

module.exports = {
data: new SlashCommandBuilder()
.setName("ping")
.setDescription("Pong!"),
run: async (client, interaction) => {
console.log(client.ws.ping)
const sent = await interaction.reply({ content: 'Ping ölçülüyor...', fetchReply: true });
sent.edit(`Ping: ${sent.createdTimestamp - interaction.createdTimestamp}ms`);
}
};
const { EmbedBuilder, PermissionsBitField } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");

module.exports = {
data: new SlashCommandBuilder()
.setName("ping")
.setDescription("Pong!"),
run: async (client, interaction) => {
console.log(client.ws.ping)
const sent = await interaction.reply({ content: 'Ping ölçülüyor...', fetchReply: true });
sent.edit(`Ping: ${sent.createdTimestamp - interaction.createdTimestamp}ms`);
}
};
My ping command
KAVI
KAVI•3y ago
The interactionCreate code I mean Did you update it
Mockir
MockirOP•3y ago
const { InteractionType } = require("discord.js");
const { users } = require('../../lib/database.js')
module.exports = {
name: 'interactionCreate',
execute: async(interaction) => {
let client = interaction.client;
if(interaction.user.bot) return;
const user = users(interaction.user.id)
if(!user) return interaction.reply('Merhaba Dostum! Seninle ilk defa karşılaşıyoruz. O yüzden bu komutu kullanmadan önce sana bir "Merhaba" demek istedim. Umarım seninle çok güzel vakit geçirebiliriz.')
if(user.banned === true) return;
const command = client.slashcommands.get(interaction.commandName)
command.run(client, interaction)
}}
const { InteractionType } = require("discord.js");
const { users } = require('../../lib/database.js')
module.exports = {
name: 'interactionCreate',
execute: async(interaction) => {
let client = interaction.client;
if(interaction.user.bot) return;
const user = users(interaction.user.id)
if(!user) return interaction.reply('Merhaba Dostum! Seninle ilk defa karşılaşıyoruz. O yüzden bu komutu kullanmadan önce sana bir "Merhaba" demek istedim. Umarım seninle çok güzel vakit geçirebiliriz.')
if(user.banned === true) return;
const command = client.slashcommands.get(interaction.commandName)
command.run(client, interaction)
}}
I did it that
KAVI
KAVI•3y ago
I said to remove the previous if statement and wrap it inside a new if statement that looks something like if (interaction.isChatInputCommand()) {...} So your code will ignore other interactions And only execute your slash commands when a slash command is used <:teri_point2:947453665164283935>
Mockir
MockirOP•3y ago
I removed? Where is it? Sorry I dont see @devkavi Bro sorry for tag but I need help
treble/luna
treble/luna•3y ago
try using console.time to see what part of your code takes so long to execute
Mockir
MockirOP•3y ago
Okey Is it true
const { EmbedBuilder, PermissionsBitField, SlashCommandBuilder } = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("ping")
.setDescription("Pong!"),
run: async (client, interaction) => {
console.time()
console.log('Here1')
console.timeEnd()
console.time()
console.log(client.ws.ping)
console.timeEnd()
console.time()
const sent = await interaction.reply({ content: 'Ping ölçülüyor...', fetchReply: true });
interaction.editReply(`Ping: ${sent.createdTimestamp - interaction.createdTimestamp}ms`);
console.timeEnd()
}
};
const { EmbedBuilder, PermissionsBitField, SlashCommandBuilder } = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("ping")
.setDescription("Pong!"),
run: async (client, interaction) => {
console.time()
console.log('Here1')
console.timeEnd()
console.time()
console.log(client.ws.ping)
console.timeEnd()
console.time()
const sent = await interaction.reply({ content: 'Ping ölçülüyor...', fetchReply: true });
interaction.editReply(`Ping: ${sent.createdTimestamp - interaction.createdTimestamp}ms`);
console.timeEnd()
}
};
Mockir
MockirOP•3y ago
Mockir
MockirOP•3y ago
Also my bot dead now He dont get any command and dont send any error
treble/luna
treble/luna•3y ago
no need to time between console;logs, time betweeon your db calls also idk how thats formatted but if that is a . and not a , then you have your answer
Mockir
MockirOP•3y ago
Currently, no commands are working, including the ping command. Isn't that the main problem?
treble/luna
treble/luna•3y ago
also show your event handler
Mockir
MockirOP•3y ago
//event-handler
readdirSync('./src/events').forEach(async file => {
const event = await require(`./src/events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
})
//event-handler
readdirSync('./src/events').forEach(async file => {
const event = await require(`./src/events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
})
treble/luna
treble/luna•3y ago
isnt require synchrounous
Mockir
MockirOP•3y ago
//event-handler
readdirSync('./src/events').forEach(async file => {
const event = await require(`./src/events/${file}`);
client.once(event.name, (...args) => event.execute(...args));
})
//event-handler
readdirSync('./src/events').forEach(async file => {
const event = await require(`./src/events/${file}`);
client.once(event.name, (...args) => event.execute(...args));
})
So is it ok?
treble/luna
treble/luna•3y ago
?? why did you do that
Mockir
MockirOP•3y ago
U said that
treble/luna
treble/luna•3y ago
no? like? I didnt even say something close to that i said that require() might not be async
Mockir
MockirOP•3y ago
Sorry ur right mb Im understand now
KAVI
KAVI•3y ago
She's right. Require is not an async operation. Sorry but I was asleep while you tagged me. And wow I forgot console.time exists. That can also help you to figure out what's taking long to execute that takes more than 3 seconds.
Mockir
MockirOP•3y ago
I try it . Probably sending Part is takes more time
treble/luna
treble/luna•3y ago
Then time it
Mockir
MockirOP•3y ago
Something happened like that
Mockir
MockirOP•3y ago
line 13.7 is await If I remove await? Its work?
treble/luna
treble/luna•3y ago
Please dont tell me those wait functions were there the whole time
Mockir
MockirOP•3y ago
No I just add I try something
treble/luna
treble/luna•3y ago
that isnt gonna help at all Just place console.time before and after each operation to see what's taking so long
Mockir
MockirOP•3y ago
I write part3 two times but
Mockir
MockirOP•3y ago
treble/luna
treble/luna•3y ago
Its taking 800ms to reply, so something is wrong with your network or machine
Mockir
MockirOP•3y ago
Mockir
MockirOP•3y ago
Ahh.. I got ws error before time Thats can be about websocket connection?
Mockir
MockirOP•3y ago
Mockir
MockirOP•3y ago
I was use .destroy before Can be thats about I dont use now

Did you find this page helpful?