0

So I'm trying to make a bot that does quick math for me via commands. My prefix is da$h and the command is payment. When I try the command da$h payment 1 + 1 for example, I'm presented with the same error every time. I'm using mathjs node btw.

I've tried putting await before send functions and async in front of all the return functions but I get the same exact error.

const math = require('mathjs');
const Discord = require('discord.js');

exports.run =  (client, message, args, tools) => {

if (!args[0]) return   message.channel.send('Please input a calculation,');

let resp;
try {
    resp = math.evaluate(args.join(' '));
} catch (e) {
    return   message.channel.send('Sorry, please input a valid calculation');
}
const embed = new Discord.RichEmbed()
.setColor(0xffffff)
.setTitle('Math Calculation')
.addField('Input', `\`\`\`${args.join(' ')}\`\`\``)
.addField('Output', `\`\`\`js${resp}\`\`\``)

 message.channel.send(embed);

}

Here's the error I keep getting:

node:18876) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message at item.request.gen.end (C:\Users\Admin\Desktop\coding\node_modules\Discord.js\src\client\rest\RequestHandlers\Sequential.js:71:65) at then (C:\Users\Admin\Desktop\coding\node_modules\snekfetch\src\index.js:204:21) at process._tickCallback (internal/process/next_tick.js:68:7) (node:18876) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2) (node:18876) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

N3R4ZZuRR0
  • 2,400
  • 4
  • 18
  • 32
Vahagn
  • 11
  • 1
  • 1

3 Answers3

1

I've usually experienced this error before myself so I am here to give you my option. First of all, in the new DiscordJS v13, it seems that a "content" field is required (for more info, please check the documentation on fields here), so this can prevent the bot from sending the message only with an embed. To check your DiscordJS version, go to your package.json folder that is located in the same folder as your index.js and check if the following versions are displayed: 13.0.0 or 13.0.1. If they are, please consider running the following on the terminal/command prompt:

npm uninstall discord.js

and then run this command to install a version that allows you to send only the embed, like v12.5.3

npm install discord.js@12.5.3

If that didn't work for you, consider running this code to create a "content" field and send the embed:

... (Your rest code)
message.channel.send('Math Calculations', { embed: embed })

and then rerun the bot. Im very happy to know if this fixed your problem. Good luck on your bot!

0

This is an embedded empty field error.

Try to use,

console.log(args.join(' '));
console.log(resp);

Then you can find what's the null field.

-1

You need to do message.channel.send({embed: embed}) for embeds with no message

Francois S.
  • 224
  • 1
  • 5
  • The `options` parameter of [`TextChannel.send()`](https://discord.js.org/#/docs/main/stable/class/TextChannel?scrollTo=send) is allowed to be a [RichEmbed](https://discord.js.org/#/docs/main/stable/class/RichEmbed) or [Attachment](https://discord.js.org/#/docs/main/stable/class/Attachment) object. – slothiful Sep 12 '19 at 22:34