mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
fix(Split/Webhook): readd message chunk sending and fix webhook avatar/username (#2085)
This commit is contained in:
@@ -10,8 +10,9 @@ module.exports = async function createMessage(channel, options) {
|
||||
const User = require('../User');
|
||||
const GuildMember = require('../GuildMember');
|
||||
const Webhook = require('../Webhook');
|
||||
const WebhookClient = require('../../client/WebhookClient');
|
||||
|
||||
const webhook = channel instanceof Webhook;
|
||||
const webhook = channel instanceof Webhook || channel instanceof WebhookClient;
|
||||
|
||||
if (typeof options.nonce !== 'undefined') {
|
||||
options.nonce = parseInt(options.nonce);
|
||||
@@ -88,15 +89,11 @@ module.exports = async function createMessage(channel, options) {
|
||||
return file;
|
||||
})
|
||||
));
|
||||
delete options.files;
|
||||
}
|
||||
|
||||
if (webhook) {
|
||||
if (!options.username) options.username = this.name;
|
||||
if (options.avatarURL) {
|
||||
options.avatar_url = options.avatarURL;
|
||||
options.avatarURL = null;
|
||||
}
|
||||
if (options.avatarURL) options.avatar_url = options.avatarURL;
|
||||
}
|
||||
|
||||
return { data: {
|
||||
@@ -106,6 +103,6 @@ module.exports = async function createMessage(channel, options) {
|
||||
embed: options.embed,
|
||||
embeds: options.embeds,
|
||||
username: options.username,
|
||||
avatar_url: options.avatarURL,
|
||||
avatar_url: options.avatar_url,
|
||||
}, files };
|
||||
};
|
||||
|
||||
@@ -7,6 +7,17 @@ module.exports = async function sendMessage(channel, options) { // eslint-disabl
|
||||
|
||||
const { data, files } = await createMessage(channel, options);
|
||||
|
||||
if (data.content instanceof Array) {
|
||||
const messages = [];
|
||||
for (let i = 0; i < data.content.length; i++) {
|
||||
const opt = i === data.content.length - 1 ? { tts: data.tts, embed: data.embed, files } : { tts: data.tts };
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const message = await channel.send(data.content[i], opt);
|
||||
messages.push(message);
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
|
||||
return channel.client.api.channels[channel.id].messages.post({ data, files })
|
||||
.then(d => channel.client.actions.MessageCreate.handle(d).message);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user