I get a error in discord that the bot don't response? how I can fix that

My code is comming
14 Replies
d.js toolkit
d.js toolkit12mo 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 OP
Nicolas Matheisen
Nicolas MatheisenOP12mo ago
const { Client } = require('clashofclans.js');
const { SlashCommandBuilder } = require('discord.js');
const { cocdevelopertoken, email, password } = require('./config.json');


const client = new Client({keys: [cocdevelopertoken], cache: true, retryLimit: 3, restRequestTimeout: 5000});


module.exports = {
data: new SlashCommandBuilder()
.setName('profile')
.setDescription('Profilecommands')
.addSubcommand(subcommand =>
subcommand
.setName('show')
.setDescription('Gets the stats of an in-game account.')
)
.addSubcommand(subcommand =>
subcommand
.setName('save')
.setDescription('Save an account as your profile.')
.addStringOption(option => option.setName('tag').setDescription('The verified tag you want to save.').setRequired(true))
)
.addSubcommand(subcommand =>
subcommand
.setName('remove')
.setDescription('Remove your profile.')
),
async execute(interaction) {


const tag = interaction.options.getString('tag');
const tagPattern = /^#[PYLQGRJCUV0289]{3,9}$/;



if (!tagPattern.test(tag)) {
interaction.channel.send(`${tag} is a invalid tag. Pls go ingame and copy ur #!`);
console.log(`${interaction.user.username} try to save a invalid tag: ${tag}.`);
return;
}

try {
const playertag = await client.getPlayer(tag);
interaction.channel.send(`I have successfully saved your tag:${tag}!` );
console.log(`${interaction.user.username} has successfully saved a tag: ${tag}.`);
} catch (error) {
if (error.reason === 'notFound') {
interaction.channel.send(`${tag} doesnt exist ingame. Pls go ingame and copy ur #!`);
console.log(`${interaction.user.username} try to save a tag: ${tag} that dosent exist ingame.` );
} else {
console.log(error);
}
}
},
};
const { Client } = require('clashofclans.js');
const { SlashCommandBuilder } = require('discord.js');
const { cocdevelopertoken, email, password } = require('./config.json');


const client = new Client({keys: [cocdevelopertoken], cache: true, retryLimit: 3, restRequestTimeout: 5000});


module.exports = {
data: new SlashCommandBuilder()
.setName('profile')
.setDescription('Profilecommands')
.addSubcommand(subcommand =>
subcommand
.setName('show')
.setDescription('Gets the stats of an in-game account.')
)
.addSubcommand(subcommand =>
subcommand
.setName('save')
.setDescription('Save an account as your profile.')
.addStringOption(option => option.setName('tag').setDescription('The verified tag you want to save.').setRequired(true))
)
.addSubcommand(subcommand =>
subcommand
.setName('remove')
.setDescription('Remove your profile.')
),
async execute(interaction) {


const tag = interaction.options.getString('tag');
const tagPattern = /^#[PYLQGRJCUV0289]{3,9}$/;



if (!tagPattern.test(tag)) {
interaction.channel.send(`${tag} is a invalid tag. Pls go ingame and copy ur #!`);
console.log(`${interaction.user.username} try to save a invalid tag: ${tag}.`);
return;
}

try {
const playertag = await client.getPlayer(tag);
interaction.channel.send(`I have successfully saved your tag:${tag}!` );
console.log(`${interaction.user.username} has successfully saved a tag: ${tag}.`);
} catch (error) {
if (error.reason === 'notFound') {
interaction.channel.send(`${tag} doesnt exist ingame. Pls go ingame and copy ur #!`);
console.log(`${interaction.user.username} try to save a tag: ${tag} that dosent exist ingame.` );
} else {
console.log(error);
}
}
},
};
Toast
Toast12mo ago
I can't answer, but correct me if I'm wrong, what I can see is that your regex is incorrect or does not match what you sent to the command.
Nicolas Matheisen
Nicolas MatheisenOP12mo ago
???? öhm ok yesterday I test it and it work well I look on youtube and the ppl do it like me
Toast
Toast12mo ago
So, it works if you pass an hashtag at the start with a string more than 3 characters long?
Nicolas Matheisen
Nicolas MatheisenOP12mo ago
jup u see my video?
Toast
Toast12mo ago
By the looks of it, if you don't pass an hashtag at the start, it gets dropped to "invalid tag" section. Yes, you didn't include the # in there.
Nicolas Matheisen
Nicolas MatheisenOP12mo ago
first i test the regex and it is wrong and the second part I don't need test cause if the regex is wrong the tag doesn't exist
duck
duck12mo ago
to respond to the error you're receiving directly, this is because you're not responding to the interaction instead, you're just sending a message to the channel normally it sounds like you're looking to use interaction.reply() instead of interaction.channel.send() interaction.reply() responds to the interaction by creating a new message
d.js docs
d.js docs12mo ago
method ChatInputCommandInteraction#reply() Creates a reply to this interaction. (more...)
Nicolas Matheisen
Nicolas MatheisenOP12mo ago
ok I must switch this only in the exist and in the save part or in all 3 ?
duck
duck12mo ago
well you can only send one initial response to the interaction, and it needs to be within 3 seconds of the interaction being created through the logic of your code, only one send should be executing (unless poor network conditions cause the "success" response to not resolve in time), so you could just replace each of them however, upon further review of your code, I'd guess that client.getPlayer() makes an api call this could potentially take longer than 3 seconds depending on network conditions, so I'd actually suggest deferring with interaction.deferReply() at the top of this function and instead replacing each send with interaction.editReply()
d.js docs
d.js docs12mo ago
method ChatInputCommandInteraction#deferReply() Defers the reply to this method ChatInputCommandInteraction#editReply() Edits a reply to this guide Slash Commands: Command response methods - Deferred responses read more
Nicolas Matheisen
Nicolas MatheisenOP12mo ago
ok I hope I understand all I sleep 2-3 hours cause it's too early and then I work and test my project And the I can tell u if it's work or not tyyy
Want results from more Discord servers?
Add your server