mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
ability to send file via sendMessage
This commit is contained in:
@@ -142,7 +142,9 @@ var InternalClient = (function () {
|
||||
ret.attach("file", file.file, file.name);
|
||||
if (data) {
|
||||
for (var i in data) {
|
||||
ret.field(i, data[i]);
|
||||
if (data[i] !== undefined) {
|
||||
ret.field(i, data[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (data) {
|
||||
@@ -701,16 +703,47 @@ var InternalClient = (function () {
|
||||
|
||||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
||||
|
||||
return this.resolver.resolveChannel(where).then(function (destination) {
|
||||
//var destination;
|
||||
var content = _this16.resolver.resolveString(_content);
|
||||
if (options.file) {
|
||||
if (typeof options.file !== "object") {
|
||||
options.file = {
|
||||
file: options.file
|
||||
};
|
||||
}
|
||||
if (!options.file.name) {
|
||||
if (options.file.file instanceof String || typeof options.file.file === "string") {
|
||||
options.file.name = require("path").basename(options.file.file);
|
||||
} else if (options.file.file.path) {
|
||||
// fs.createReadStream()'s have .path that give the path. Not sure about other streams though.
|
||||
options.file.name = require("path").basename(options.file.file.path);
|
||||
} else {
|
||||
options.file.name = "default.png"; // Just have to go with default filenames.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _this16.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(destination.id), true, {
|
||||
content: content,
|
||||
tts: options.tts
|
||||
}).then(function (res) {
|
||||
return destination.messages.add(new _StructuresMessage2["default"](res, destination, _this16.client));
|
||||
});
|
||||
return this.resolver.resolveChannel(where).then(function (destination) {
|
||||
if (options.file) {
|
||||
return _this16.resolver.resolveFile(options.file.file).then(function (file) {
|
||||
return _this16.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(destination.id), true, {
|
||||
content: _content,
|
||||
tts: options.tts
|
||||
}, {
|
||||
name: options.file.name,
|
||||
file: file
|
||||
}).then(function (res) {
|
||||
return destination.messages.add(new _StructuresMessage2["default"](res, destination, _this16.client));
|
||||
});
|
||||
});
|
||||
} else {
|
||||
var content = _this16.resolver.resolveString(_content);
|
||||
|
||||
return _this16.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(destination.id), true, {
|
||||
content: content,
|
||||
tts: options.tts
|
||||
}).then(function (res) {
|
||||
return destination.messages.add(new _StructuresMessage2["default"](res, destination, _this16.client));
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -730,11 +763,15 @@ var InternalClient = (function () {
|
||||
}
|
||||
}
|
||||
|
||||
if (content) {
|
||||
content = {
|
||||
content: content
|
||||
};
|
||||
}
|
||||
|
||||
return this.resolver.resolveChannel(where).then(function (channel) {
|
||||
return _this17.resolver.resolveFile(_file).then(function (file) {
|
||||
return _this17.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(channel.id), true, {
|
||||
content: content
|
||||
}, {
|
||||
return _this17.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(channel.id), true, content, {
|
||||
name: name,
|
||||
file: file
|
||||
}).then(function (res) {
|
||||
|
||||
Reference in New Issue
Block a user