Great question, this is less of a discord.js question, rather a how to format a .then
.
You can either carry on in the function after .then or use an async/await.
First method:
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const { commandName } = interaction;
if (commandName === 'denick') {
await interaction.deferReply();
const data = fetch('http://api.antisniper.net/account/api_disabled/counts')
.then(async response => {
var jsonResponse = await response.json();
var jsonToString = JSON.stringify(jsonResponse)
interaction.editReply({ content: data });
});
}
});
As you can see above, I've shifted everything after the .then
function. I've also done an await response.json() and a stringify. Missing either of those will send an error(either the error you got or [Object object]).
The second method:
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const { commandName } = interaction;
if (commandName === 'denick') {
await interaction.deferReply();
const data = await fetch('http://api.antisniper.net/account/api_disabled/counts');
var jsonResponse = await data.json();
var jsonToString = JSON.stringify(jsonResponse)
interaction.editReply({ content: data });
}
});
I've removed the .then function and replaced it with an await. The rest is the same.
Either methods should be able to work, if it helped, please remember to mark the question as correct, if there's any problems, please comment!
Edit:
To only show the winstreak_data_hidden
data, simply use the returned jsonResponse as a object.
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const { commandName } = interaction;
if (commandName === 'denick') {
await interaction.deferReply();
const data = await fetch('http://api.antisniper.net/account/api_disabled/counts');
var jsonResponse = await data.json();
var hiddenWinStreakData = jsonResponse.winstreak_data_hidden;
if(hiddenWinStreakData){
interaction.editReply({ content: hiddenWinStreakData });
}
}
});
I've done a simple if statement to avoid discord throwing errors, you can also do an else statement after to say that the user doesn't have hidden win streak data. Hope this helped!