mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
Updated tests and added file sending
This commit is contained in:
@@ -551,7 +551,20 @@ var Client = (function () {
|
|||||||
self.resolveDestination(destination).then(send)["catch"](error);
|
self.resolveDestination(destination).then(send)["catch"](error);
|
||||||
|
|
||||||
function send(destination) {
|
function send(destination) {
|
||||||
request.post(Endpoints.CHANNELS + "/" + destination + "/messages");
|
request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).attach("file", fstream, fileName).end(function (err, res) {
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
error(err);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
var chann = self.getChannel("id", destination);
|
||||||
|
if (chann) {
|
||||||
|
var msg = chann.addMessage(new Message(res.body, chann, [], self.user));
|
||||||
|
callback(null, msg);
|
||||||
|
resolve(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function error(err) {
|
function error(err) {
|
||||||
|
|||||||
@@ -558,15 +558,34 @@ class Client {
|
|||||||
} else {
|
} else {
|
||||||
fstream = file;
|
fstream = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.resolveDestination(destination).then(send).catch(error);
|
self.resolveDestination(destination).then(send).catch(error);
|
||||||
|
|
||||||
function send(destination) {
|
function send(destination) {
|
||||||
request
|
request
|
||||||
.post(`${Endpoints.CHANNELS}/${destination}/messages`)
|
.post(`${Endpoints.CHANNELS}/${destination}/messages`)
|
||||||
|
.set("authorization", self.token)
|
||||||
|
.attach("file", fstream, fileName)
|
||||||
|
.end(function (err, res) {
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
error(err);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
var chann = self.getChannel("id", destination);
|
||||||
|
if (chann) {
|
||||||
|
var msg = chann.addMessage(new Message(res.body, chann, [], self.user));
|
||||||
|
callback(null, msg);
|
||||||
|
resolve(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function error(err){
|
function error(err) {
|
||||||
callback(err);
|
callback(err);
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
@@ -585,7 +604,7 @@ class Client {
|
|||||||
var mentions = resolveMentions();
|
var mentions = resolveMentions();
|
||||||
self.resolveDestination(destination).then(send).catch(error);
|
self.resolveDestination(destination).then(send).catch(error);
|
||||||
|
|
||||||
function error(err){
|
function error(err) {
|
||||||
callback(err);
|
callback(err);
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
|
|||||||
11
test/bot.js
11
test/bot.js
@@ -79,11 +79,18 @@ function success12(_server){
|
|||||||
|
|
||||||
function success13(){
|
function success13(){
|
||||||
console.log("test 12 successful");
|
console.log("test 12 successful");
|
||||||
mybot.leaveServer(server).then(success14).catch(error);
|
mybot.sendFile(server, "./test/image.png").then(function(msg){
|
||||||
|
mybot.deleteMessage(msg).then(success14).catch(error);
|
||||||
|
}).catch(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
function success14(){
|
function success14(msg){
|
||||||
console.log("test 13 successful");
|
console.log("test 13 successful");
|
||||||
|
mybot.leaveServer(server).then(success15).catch(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
function success15(){
|
||||||
|
console.log("test 14 successful");
|
||||||
mybot.logout().then(done).catch(error);
|
mybot.logout().then(done).catch(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
BIN
test/image.png
Normal file
BIN
test/image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Reference in New Issue
Block a user