slash command reply taking a minute or two to send message despite logging fine

(the code was too big for the message it's after this one) context: I'm working on a mod of the api and for some reason when I run the command it won't reply or send messages but it'll log just fine then it'll wait for a few minutes and only then will it try to send a message. the only time I get an error is if I use reply but since it took so long it can't even get the reply so it says unknown interaction. I've asked a few of my other developer friends if they know why it's happening and none of the ideas they've given me have worked nor do they have any idea why it's happening.
14 Replies
d.js toolkit
d.js toolkit17mo 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!
cup 🗕 🗗 🗙
cup 🗕 🗗 🗙OP17mo ago
this is the stuff for the command:
var { wc, bot } = require('../../index.js')

let options = [
{
name: "user",
description: "user to get",
type: "user"
}
]

async function action(ctx, cmd) {
let user = (cmd.args[0]) ? await wc.fetchUser(cmd.args[0].value) : ctx.user

await ctx.reply(wc.user.avatar(user))
}

(async () => {
await wc.slashCommand({ name: "avatar", desc: "Sends a user's avatar", options: options}, action);
})()
var { wc, bot } = require('../../index.js')

let options = [
{
name: "user",
description: "user to get",
type: "user"
}
]

async function action(ctx, cmd) {
let user = (cmd.args[0]) ? await wc.fetchUser(cmd.args[0].value) : ctx.user

await ctx.reply(wc.user.avatar(user))
}

(async () => {
await wc.slashCommand({ name: "avatar", desc: "Sends a user's avatar", options: options}, action);
})()
function code:
async slashCommand(info={name:null, description:null, options:null, cooldown:null, nsfw:false}, dataA, dataB=null) {
if (typeof info == "string") {
let thing = info;
info = { name: thing, description:null, options:null, cooldown:null, nsfw:false };
}

if (info.options && info.options instanceof Array) {
var options = Soup.from(info.options)

options = options.map( (v) => {
v.type = this.optionType(v.type);
if (v.desc && !v.description) v.description = v.desc;
return v;
})
}

if (info.desc && !info.description) info.description = info.desc

var data
if (typeof dataA == "string" && !info.description) {
info.description = dataA
data = dataB
}
else if (info.description) {
data = dataA
}


var [name, description] = [info.name, info.description];


if (info.cooldown && typeof info.cooldown == "number") { var time = info.cooldown; }
else if (info.cooldown && typeof info.cooldown == "string") { var time = this.time.parse(info.cooldown); }
else if (info.cooldown) { throw new CoolError("Slash Command Creation", 'Invalid cooldown. ( cooldown: 3 | cooldown: "3s" )'); }


if (!name || typeof name != "string" || name.length <= 0) {
throw new CoolError("Slash Command Creation", "Invalid slash command name.\n\nPossible reasons:\n • doesn't exist\n • not a string\n • blank string\n\nActual error stuff:");
}

if (!description || typeof description != "string" || description.length <= 0) {
throw new CoolError("Slash Command Creation", "Invalid slash command description.\n\nPossible reasons:\n • not a string\n • blank string\n\nActual error stuff:");
}


if (info.cooldown) {
if (typeof time != "number") {
throw new CoolError("Slash Command Creation", "Cooldown has to be an integer (seconds)");
}


info.cooldown = {
data: new Set(),
active: true,
time: time,

get relative() {
var [wc, client, ctx] = Holder;
let now = parseInt(wc.time.now.relative.split(":")[1]);
let raw = Math.abs( info.cooldown.time + parseInt(now) );
return `<t:${raw}:R>`;
},


get raw() {
var [wc, client, ctx] = Holder;
let now = parseInt(wc.time.now.relative.split(":")[1]);
return Math.abs( info.cooldown.time + parseInt(now) );
},


handle(user=null) {
var [wc, client, ctx] = Holder;

user = (user) ? user : ctx.user;

if (!this.data.has(user.id)) {
this.data.add(user.id);

setTimeout( () => { this.data.delete(user.id); }, this.time*1000);
}
},


fetch(user=null) {
var [wc, client, ctx] = Holder;
return (this.data.has( (user) ? user.id : ctx.user.id )) ? true : false;
}
};
}

let newCMD = {"info": Soup.from(info), "data": data};
this.slashCommandList.push(info.name, newCMD);

var commands = this.slashCommandList.values.map( (command) => {
return command.info.toJSON()
});


fetch('https://discordapp.com/api/oauth2/applications/@me', {
headers: {
authorization: `Bot ${this.token}`,
},
})

.then(result => result.json())
.then( async (response) => {
const { id } = response;

await this.rest.put(
Routes.applicationCommands(id),
{ body: commands }
);
})
.catch(console.error);


return newCMD;
}
async slashCommand(info={name:null, description:null, options:null, cooldown:null, nsfw:false}, dataA, dataB=null) {
if (typeof info == "string") {
let thing = info;
info = { name: thing, description:null, options:null, cooldown:null, nsfw:false };
}

if (info.options && info.options instanceof Array) {
var options = Soup.from(info.options)

options = options.map( (v) => {
v.type = this.optionType(v.type);
if (v.desc && !v.description) v.description = v.desc;
return v;
})
}

if (info.desc && !info.description) info.description = info.desc

var data
if (typeof dataA == "string" && !info.description) {
info.description = dataA
data = dataB
}
else if (info.description) {
data = dataA
}


var [name, description] = [info.name, info.description];


if (info.cooldown && typeof info.cooldown == "number") { var time = info.cooldown; }
else if (info.cooldown && typeof info.cooldown == "string") { var time = this.time.parse(info.cooldown); }
else if (info.cooldown) { throw new CoolError("Slash Command Creation", 'Invalid cooldown. ( cooldown: 3 | cooldown: "3s" )'); }


if (!name || typeof name != "string" || name.length <= 0) {
throw new CoolError("Slash Command Creation", "Invalid slash command name.\n\nPossible reasons:\n • doesn't exist\n • not a string\n • blank string\n\nActual error stuff:");
}

if (!description || typeof description != "string" || description.length <= 0) {
throw new CoolError("Slash Command Creation", "Invalid slash command description.\n\nPossible reasons:\n • not a string\n • blank string\n\nActual error stuff:");
}


if (info.cooldown) {
if (typeof time != "number") {
throw new CoolError("Slash Command Creation", "Cooldown has to be an integer (seconds)");
}


info.cooldown = {
data: new Set(),
active: true,
time: time,

get relative() {
var [wc, client, ctx] = Holder;
let now = parseInt(wc.time.now.relative.split(":")[1]);
let raw = Math.abs( info.cooldown.time + parseInt(now) );
return `<t:${raw}:R>`;
},


get raw() {
var [wc, client, ctx] = Holder;
let now = parseInt(wc.time.now.relative.split(":")[1]);
return Math.abs( info.cooldown.time + parseInt(now) );
},


handle(user=null) {
var [wc, client, ctx] = Holder;

user = (user) ? user : ctx.user;

if (!this.data.has(user.id)) {
this.data.add(user.id);

setTimeout( () => { this.data.delete(user.id); }, this.time*1000);
}
},


fetch(user=null) {
var [wc, client, ctx] = Holder;
return (this.data.has( (user) ? user.id : ctx.user.id )) ? true : false;
}
};
}

let newCMD = {"info": Soup.from(info), "data": data};
this.slashCommandList.push(info.name, newCMD);

var commands = this.slashCommandList.values.map( (command) => {
return command.info.toJSON()
});


fetch('https://discordapp.com/api/oauth2/applications/@me', {
headers: {
authorization: `Bot ${this.token}`,
},
})

.then(result => result.json())
.then( async (response) => {
const { id } = response;

await this.rest.put(
Routes.applicationCommands(id),
{ body: commands }
);
})
.catch(console.error);


return newCMD;
}
when I run the command it logs in my console but it doesn't reply
cup 🗕 🗗 🗙
cup 🗕 🗗 🗙OP17mo ago
No description
cup 🗕 🗗 🗙
cup 🗕 🗗 🗙OP17mo ago
No description
invictus
invictus17mo ago
Have you tried .deferReply() to extend the reply time limit and see whether the reply will actually land?
cup 🗕 🗗 🗙
cup 🗕 🗗 🗙OP17mo ago
I've tried putting await ctx.deferReply() before the reply and it worked once then stopped working every time afterwards
invictus
invictus17mo ago
"stopped working" as in there is no reply till the token expires? (15 min)
cup 🗕 🗗 🗙
cup 🗕 🗗 🗙OP17mo ago
it did the same thing as it did without it where it'd say that it was getting the command for a few seconds then it would say that the application didn't respond
invictus
invictus17mo ago
That's weird. That means the .deferReply() doesn't even run. Do you perhaps have another listener for the command that runs prior to that?
cup 🗕 🗗 🗙
cup 🗕 🗗 🗙OP17mo ago
there should only be one listener for it that I put in the constructor
constructor(settings) {
this.client = settings.client;
this.prefix = settings.prefix;
this.token = settings.token;

this.rest = new REST().setToken(this.token)

console.log("willclient started");

// prefix commands
this.client.on("messageCreate", async (ctx) => {
Holder = [this, this.client, ctx];
await this.commandHandler(ctx);
});


// slash commands
this.client.on("interactionCreate", async (ctx) => {
if (ctx.isChatInputCommand()) {
Holder = [this, this.client, ctx];

await this.slashCommandHandler(ctx);
}
})
}
constructor(settings) {
this.client = settings.client;
this.prefix = settings.prefix;
this.token = settings.token;

this.rest = new REST().setToken(this.token)

console.log("willclient started");

// prefix commands
this.client.on("messageCreate", async (ctx) => {
Holder = [this, this.client, ctx];
await this.commandHandler(ctx);
});


// slash commands
this.client.on("interactionCreate", async (ctx) => {
if (ctx.isChatInputCommand()) {
Holder = [this, this.client, ctx];

await this.slashCommandHandler(ctx);
}
})
}
invictus
invictus17mo ago
I see I just noticed, I think you miss function keyword at the beginning. You don't get error from that? Because it shouldn't be valid.
cup 🗕 🗗 🗙
cup 🗕 🗗 🗙OP17mo ago
it's inside of a class you don't need the function keyword for those
invictus
invictus17mo ago
Oh I see. I thought it's an independent function
cup 🗕 🗗 🗙
cup 🗕 🗗 🗙OP17mo ago
as far as I know despite how weird my methods of registering commands were (it was for simplicity because I didn't want the user to go through the hassle of getting the application id so I made it where they could just put in the token and it'd use cool api stuff to get the id for them and register it) I don't believe that it's because of problems with registering or anything everyone I've talked to has said that it should work
Want results from more Discord servers?
Add your server