Discord.js send files

2019-02-21 02:48发布

问题:

I can't remember how long ago it was, but Discord.js updated in the time that I was away and not coding. One of the things that was updated and will be removed in 1.12 (or so I'm told) is the sendFile option. sendFile, senMessage, etc. are all under a single 'send' now. I haven't had any trouble with it till I went to go make a command where a user gets a file from an /images folder.

What I'm referring to. Any help would be appreciated. And it goes without saying, but I'm decently new to coding, along with the Discord.js lib.

回答1:

I figured it out with the help of moi good ol' pall Matt. The code looks around something like this if anyone else stumbles upon this.

message.channel.send(`Testing message.`, {
  files: [
    "./images/headpat1.png"
  ]
})

EDIT: You can read more about these properties, methods and paramters here Discord.js - stable release - textChannel#send()



回答2:

The sendFile method has been deprecated because they wanted to implement DataStore to increase efficiency of the API. You need to use send instead of sendFile to avoid errors in future.

/* File should wrapped in an array! */
message.channel.send({
    files: ['./images/blackman-harris.png']
});

Other users, send an excessive text message with the file. It's optional to send a text along with with file. Further more information is available on the wiki page for send method.