mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 17:13:31 +01:00
Merge branch 'master' into indev-prism
This commit is contained in:
@@ -123,6 +123,19 @@ class ClientDataResolver {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a ChannelResolvable to a Channel object
|
||||
* @param {ChannelResolvable} channel The channel resolvable to resolve
|
||||
* @returns {?string}
|
||||
*/
|
||||
resolveChannelID(channel) {
|
||||
if (channel instanceof Channel) return channel.id;
|
||||
if (typeof channel === 'string') return channel;
|
||||
if (channel instanceof Message) return channel.channel.id;
|
||||
if (channel instanceof Guild) return channel.defaultChannel.id;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data that can be resolved to give an invite code. This can be:
|
||||
* * An invite code
|
||||
|
||||
@@ -3,6 +3,7 @@ const Collection = require('../../util/Collection');
|
||||
const splitMessage = require('../../util/SplitMessage');
|
||||
const parseEmoji = require('../../util/ParseEmoji');
|
||||
const escapeMarkdown = require('../../util/EscapeMarkdown');
|
||||
const transformSearchOptions = require('../../util/TransformSearchOptions');
|
||||
|
||||
const User = require('../../structures/User');
|
||||
const GuildMember = require('../../structures/GuildMember');
|
||||
@@ -12,6 +13,8 @@ const Invite = require('../../structures/Invite');
|
||||
const Webhook = require('../../structures/Webhook');
|
||||
const UserProfile = require('../../structures/UserProfile');
|
||||
const ClientOAuth2Application = require('../../structures/ClientOAuth2Application');
|
||||
const Channel = require('../../structures/Channel');
|
||||
const Guild = require('../../structures/Guild');
|
||||
|
||||
class RESTMethods {
|
||||
constructor(restManager) {
|
||||
@@ -117,6 +120,30 @@ class RESTMethods {
|
||||
);
|
||||
}
|
||||
|
||||
search(target, options) {
|
||||
options = transformSearchOptions(options, this.client);
|
||||
|
||||
const queryString = Object.keys(options)
|
||||
.filter(k => options[k])
|
||||
.map(k => [k, options[k]])
|
||||
.map(x => x.join('='))
|
||||
.join('&');
|
||||
|
||||
let type;
|
||||
if (target instanceof Channel) {
|
||||
type = 'channel';
|
||||
} else if (target instanceof Guild) {
|
||||
type = 'guild';
|
||||
} else {
|
||||
throw new TypeError('Target must be a TextChannel, DMChannel, GroupDMChannel, or Guild.');
|
||||
}
|
||||
|
||||
const url = `${Constants.Endpoints[`${type}Search`](target.id)}?${queryString}`;
|
||||
return this.rest.makeRequest('get', url, true).then(body =>
|
||||
body.messages.map(x => x.map(m => new Message(this.client.channels.get(m.channel_id), m, this.client)))
|
||||
);
|
||||
}
|
||||
|
||||
createChannel(guild, channelName, channelType, overwrites) {
|
||||
if (overwrites instanceof Collection) overwrites = overwrites.array();
|
||||
return this.rest.makeRequest('post', Constants.Endpoints.guildChannels(guild.id), true, {
|
||||
|
||||
Reference in New Issue
Block a user