Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Discord bot send picture with message with NodeJS

I have a few pictures, all on imgur with direct image link (format: https://i.imgur.com/XXXXXX.jpg), and a Discord bot made with NodeJS.

I send messages like this:

bot.sendMessage({
    to: channelID,
    message: "My Bot's message"
});

I have tried this:

bot.sendMessage({
    to: channelID,
    message: "My Bot's message",
    file: "https://i.imgur.com/XxxXxXX.jpg"
});

but I only get the text. I have looked it up, and this question was the only one to even come close to saying what I need to do, and it didn't work.

So how am I supposed to do this?

Here is how the bot is created:

var bot = new Discord.Client({
   token: auth.token,
   autorun: true
});
bot.on('ready', function (evt) {
    logger.info('Connected');
    logger.info('Logged in as: ');
    logger.info(bot.username + ' - (' + bot.id + ')');
});
bot.on('message', function (user, userID, channelID, message, evt) {
    // My code
}
like image 362
Kaito Kid Avatar asked Aug 14 '17 23:08

Kaito Kid


1 Answers

ClientUser.sendMessage is deprecated, as is the file parameter in its options. You should be using Channel.send(message, options), with files as an array of strings or FileOptions.

bot.on('messageCreate' message => {
    message.channel.send("My Bot's message", {files: ["https://i.imgur.com/XxxXxXX.jpg"]});
});

If you want to stick to your deprecated methods, ClientUser.sendFile might be something of interest to you, though I do recommend you move over to the stuff that's more current.

like image 129
Kae Avatar answered Oct 18 '22 09:10

Kae