mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat(GuildManager): add AFK and system channel options in create (#4837)
This commit adds support for the `afk_channel_id`, `afk_timeout`, and `system_channel_id` parameters in the [create guild](https://discord.com/developers/docs/resources/guild#create-guild-json-params) endpoint by adding the `afkChannelID`, `afkTimeout`, and `systemChannelID` options in `GuildManager#create`. This commit also fixes a minor bug in `create` when specifying types for the channels due to the channel types not being changed from `'text'`, `'voice'` etc to the corresponding numbers, so Discord would return an error.
This commit is contained in:
@@ -8,6 +8,7 @@ const GuildMember = require('../structures/GuildMember');
|
|||||||
const Invite = require('../structures/Invite');
|
const Invite = require('../structures/Invite');
|
||||||
const Role = require('../structures/Role');
|
const Role = require('../structures/Role');
|
||||||
const {
|
const {
|
||||||
|
ChannelTypes,
|
||||||
Events,
|
Events,
|
||||||
VerificationLevels,
|
VerificationLevels,
|
||||||
DefaultMessageNotifications,
|
DefaultMessageNotifications,
|
||||||
@@ -129,6 +130,8 @@ class GuildManager extends BaseManager {
|
|||||||
* <warn>This is only available to bots in fewer than 10 guilds.</warn>
|
* <warn>This is only available to bots in fewer than 10 guilds.</warn>
|
||||||
* @param {string} name The name of the guild
|
* @param {string} name The name of the guild
|
||||||
* @param {Object} [options] Options for the creating
|
* @param {Object} [options] Options for the creating
|
||||||
|
* @param {number} [options.afkChannelID] The ID of the AFK channel
|
||||||
|
* @param {number} [options.afkTimeout] The AFK timeout in seconds
|
||||||
* @param {PartialChannelData[]} [options.channels] The channels for this guild
|
* @param {PartialChannelData[]} [options.channels] The channels for this guild
|
||||||
* @param {DefaultMessageNotifications} [options.defaultMessageNotifications] The default message notifications
|
* @param {DefaultMessageNotifications} [options.defaultMessageNotifications] The default message notifications
|
||||||
* for the guild
|
* for the guild
|
||||||
@@ -137,18 +140,22 @@ class GuildManager extends BaseManager {
|
|||||||
* @param {string} [options.region] The region for the server, defaults to the closest one available
|
* @param {string} [options.region] The region for the server, defaults to the closest one available
|
||||||
* @param {PartialRoleData[]} [options.roles] The roles for this guild,
|
* @param {PartialRoleData[]} [options.roles] The roles for this guild,
|
||||||
* the first element of this array is used to change properties of the guild's everyone role.
|
* the first element of this array is used to change properties of the guild's everyone role.
|
||||||
|
* @param {number} [options.systemChannelID] The ID of the system channel
|
||||||
* @param {VerificationLevel} [options.verificationLevel] The verification level for the guild
|
* @param {VerificationLevel} [options.verificationLevel] The verification level for the guild
|
||||||
* @returns {Promise<Guild>} The guild that was created
|
* @returns {Promise<Guild>} The guild that was created
|
||||||
*/
|
*/
|
||||||
async create(
|
async create(
|
||||||
name,
|
name,
|
||||||
{
|
{
|
||||||
|
afkChannelID,
|
||||||
|
afkTimeout,
|
||||||
channels = [],
|
channels = [],
|
||||||
defaultMessageNotifications,
|
defaultMessageNotifications,
|
||||||
explicitContentFilter,
|
explicitContentFilter,
|
||||||
icon = null,
|
icon = null,
|
||||||
region,
|
region,
|
||||||
roles = [],
|
roles = [],
|
||||||
|
systemChannelID,
|
||||||
verificationLevel,
|
verificationLevel,
|
||||||
} = {},
|
} = {},
|
||||||
) {
|
) {
|
||||||
@@ -163,6 +170,7 @@ class GuildManager extends BaseManager {
|
|||||||
explicitContentFilter = ExplicitContentFilterLevels.indexOf(explicitContentFilter);
|
explicitContentFilter = ExplicitContentFilterLevels.indexOf(explicitContentFilter);
|
||||||
}
|
}
|
||||||
for (const channel of channels) {
|
for (const channel of channels) {
|
||||||
|
if (channel.type) channel.type = ChannelTypes[channel.type.toUpperCase()];
|
||||||
channel.parent_id = channel.parentID;
|
channel.parent_id = channel.parentID;
|
||||||
delete channel.parentID;
|
delete channel.parentID;
|
||||||
if (!channel.permissionOverwrites) continue;
|
if (!channel.permissionOverwrites) continue;
|
||||||
@@ -187,8 +195,11 @@ class GuildManager extends BaseManager {
|
|||||||
verification_level: verificationLevel,
|
verification_level: verificationLevel,
|
||||||
default_message_notifications: defaultMessageNotifications,
|
default_message_notifications: defaultMessageNotifications,
|
||||||
explicit_content_filter: explicitContentFilter,
|
explicit_content_filter: explicitContentFilter,
|
||||||
channels,
|
|
||||||
roles,
|
roles,
|
||||||
|
channels,
|
||||||
|
afk_channel_id: afkChannelID,
|
||||||
|
afk_timeout: afkTimeout,
|
||||||
|
system_channel_id: systemChannelID,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
|||||||
31
test/createGuild.js
Normal file
31
test/createGuild.js
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
const { token } = require('./auth');
|
||||||
|
const { Client } = require('../src');
|
||||||
|
|
||||||
|
const client = new Client();
|
||||||
|
|
||||||
|
client.on('ready', async () => {
|
||||||
|
try {
|
||||||
|
const guild = await client.guilds.create('testing', {
|
||||||
|
channels: [
|
||||||
|
{ name: 'afk channel', type: 'voice', id: 0 },
|
||||||
|
{ name: 'system-channel', id: 1 },
|
||||||
|
],
|
||||||
|
afkChannelID: 0,
|
||||||
|
afkTimeout: 60,
|
||||||
|
systemChannelID: 1,
|
||||||
|
});
|
||||||
|
console.log(guild.id);
|
||||||
|
assert.strictEqual(guild.afkChannel.name, 'afk channel');
|
||||||
|
assert.strictEqual(guild.afkTimeout, 60);
|
||||||
|
assert.strictEqual(guild.systemChannel.name, 'system-channel');
|
||||||
|
await guild.delete();
|
||||||
|
client.destroy();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
client.login(token).catch(console.error);
|
||||||
18
typings/index.d.ts
vendored
18
typings/index.d.ts
vendored
@@ -1941,10 +1941,7 @@ declare module 'discord.js' {
|
|||||||
|
|
||||||
export class GuildManager extends BaseManager<Snowflake, Guild, GuildResolvable> {
|
export class GuildManager extends BaseManager<Snowflake, Guild, GuildResolvable> {
|
||||||
constructor(client: Client, iterable?: Iterable<any>);
|
constructor(client: Client, iterable?: Iterable<any>);
|
||||||
public create(
|
public create(name: string, options?: GuildCreateOptions): Promise<Guild>;
|
||||||
name: string,
|
|
||||||
options?: { region?: string; icon: BufferResolvable | Base64Resolvable | null },
|
|
||||||
): Promise<Guild>;
|
|
||||||
public fetch(id: Snowflake, cache?: boolean, force?: boolean): Promise<Guild>;
|
public fetch(id: Snowflake, cache?: boolean, force?: boolean): Promise<Guild>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2577,6 +2574,19 @@ declare module 'discord.js' {
|
|||||||
name?: string;
|
name?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface GuildCreateOptions {
|
||||||
|
afkChannelID?: number;
|
||||||
|
afkTimeout?: number;
|
||||||
|
channels?: PartialChannelData[];
|
||||||
|
defaultMessageNotifications?: DefaultMessageNotifications | number;
|
||||||
|
explicitContentFilter?: ExplicitContentFilterLevel | number;
|
||||||
|
icon?: BufferResolvable | Base64Resolvable | null;
|
||||||
|
region?: string;
|
||||||
|
roles?: PartialRoleData[];
|
||||||
|
systemChannelID?: number;
|
||||||
|
verificationLevel?: VerificationLevel | number;
|
||||||
|
}
|
||||||
|
|
||||||
interface GuildWidget {
|
interface GuildWidget {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
channel: GuildChannel | null;
|
channel: GuildChannel | null;
|
||||||
|
|||||||
Reference in New Issue
Block a user