Discord.js something-random-on-discord meme API not working: DiscordAPIError: Cannot send an empty message
I am new to working with APIs in discord.js and I stumbled across a meme API in npm (https://www.npmjs.com/package/something-random-on-discord). I followed the exact steps on the site and got this error:
/home/runner/Penguin69/node_modules/discord.js/src/rest/RequestHandler.js:349
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (/home/runner/Penguin69/node_modules/discord.js/src/rest/RequestHandler.js:349:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/home/runner/Penguin69/node_modules/discord.js/src/rest/RequestHandler.js:50:14) {
method: 'post',
path: '/channels/914839917769658371/messages',
code: 50006,
httpStatus: 400,
requestData: {
json: {
content: undefined,
tts: false,
nonce: undefined,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined
},
files: []
}
}
my code was:
const random = require("something-random-on-discord").Random
client.on("messageCreate", message => {
if (message.content.toLowerCase() === "!meme") {
let data = await random.getMeme()
message.channel.send(data)
};
});
Does this have something to do with me using discord.js v13? If so, is there any other meme API/generator that works? Hope someone can help!
I also found this other meme api: random-jokes-api
It worked super well for me on my bot so it should work for you!
You would just use the following:
const Memer = require("random-jokes-api")
const Discord = require("discord.js")
const bot = new Discord.Client()
// Listen to the ready event
bot.on("ready", () => {
console.log("Ready!");
})
// Listen to the message event
bot.on("message", async (message) => {
if (message.content === "meme") {
let meme = Memer.meme()
let embed = new Discord.MessageEmbed()
.setTitle(meme.title)
.setImage(meme.url)
.setFooter(`Categroy: ${meme.category}`)
message.channel.send(embed)
}
})