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