1
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(response => response.json());
    
    interaction.editReply({ content: data });
  }
});

ERROR:

if (typeof data !== 'string') throw new error(errorMessage);
RangeError [MESSAGE_CONTENT_TYPE]: Message content must be a non-empty string.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
birdlol
  • 21
  • 2

1 Answers1

0

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!

Jeffplays2005
  • 172
  • 15
  • Hey! Thanks for the response however I got this small error [code](https://paste-bin.xyz/42219) `{ "success": true, "data": { "online_status_hidden": 50763, "winstreak_data_hidden": 28628 } } ` Here is what the json page shows and I want to make the bot say the ""winstreak_data_hidden"". Thank you for the help! – birdlol Mar 09 '22 at 01:29
  • I'll edit the answer according to your suggestion! – Jeffplays2005 Mar 09 '22 at 03:55