feat: update OAuth2 authorization options and add method warnings for deprecated functionality
This commit is contained in:
@@ -19,11 +19,14 @@ const client = new Discord.Client({
|
|||||||
|
|
||||||
client.on('ready', async () => {
|
client.on('ready', async () => {
|
||||||
console.log('Ready!', client.user.tag);
|
console.log('Ready!', client.user.tag);
|
||||||
|
// Note
|
||||||
|
// You need to include `guild_id` and `permissions` to invite the bot.
|
||||||
|
// These two fields can appear either in the URL or in the options.
|
||||||
await client.authorizeURL(
|
await client.authorizeURL(
|
||||||
`https://discord.com/api/oauth2/authorize?client_id=289066747443675143&permissions=414501424448&scope=bot%20applications.commands`,
|
`https://discord.com/api/oauth2/authorize?client_id=289066747443675143&permissions=414501424448&scope=bot%20applications.commands`,
|
||||||
{
|
{
|
||||||
guild_id: 'guild id',
|
guild_id: 'guild id',
|
||||||
permissions: '8', // Admin
|
permissions: '414501424448',
|
||||||
authorize: true,
|
authorize: true,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -588,6 +588,7 @@ class Client extends BaseClient {
|
|||||||
* await client.acceptInvite('https://discord.gg/genshinimpact', { bypassOnboarding: true, bypassVerify: true })
|
* await client.acceptInvite('https://discord.gg/genshinimpact', { bypassOnboarding: true, bypassVerify: true })
|
||||||
*/
|
*/
|
||||||
async acceptInvite(invite, options = { bypassOnboarding: true, bypassVerify: true }) {
|
async acceptInvite(invite, options = { bypassOnboarding: true, bypassVerify: true }) {
|
||||||
|
throw new Error('METHOD_WARNING');
|
||||||
const code = DataResolver.resolveInviteCode(invite);
|
const code = DataResolver.resolveInviteCode(invite);
|
||||||
if (!code) throw new Error('INVITE_RESOLVE_CODE');
|
if (!code) throw new Error('INVITE_RESOLVE_CODE');
|
||||||
const i = await this.fetchInvite(code);
|
const i = await this.fetchInvite(code);
|
||||||
@@ -709,7 +710,8 @@ class Client extends BaseClient {
|
|||||||
authorize: true
|
authorize: true
|
||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
authorizeURL(url, options = { authorize: true, permissions: '0' }) {
|
authorizeURL(url, options = { authorize: true }) {
|
||||||
|
throw new Error('METHOD_WARNING');
|
||||||
const pathnameAPI = /\/api\/(v\d{1,2}\/)?oauth2\/authorize/;
|
const pathnameAPI = /\/api\/(v\d{1,2}\/)?oauth2\/authorize/;
|
||||||
const pathnameURL = /\/oauth2\/authorize/;
|
const pathnameURL = /\/oauth2\/authorize/;
|
||||||
const url_ = new URL(url);
|
const url_ = new URL(url);
|
||||||
@@ -720,8 +722,19 @@ class Client extends BaseClient {
|
|||||||
throw new Error('INVALID_URL', url);
|
throw new Error('INVALID_URL', url);
|
||||||
}
|
}
|
||||||
const searchParams = Object.fromEntries(url_.searchParams);
|
const searchParams = Object.fromEntries(url_.searchParams);
|
||||||
options.permissions = `${Permissions.resolve(searchParams.permissions || options.permissions) || 0}`;
|
options.permissions ??= `${Permissions.resolve(searchParams.permissions || 0)}`;
|
||||||
|
options.integration_type ??= searchParams.integration_type || 0;
|
||||||
|
options.location_context = {
|
||||||
|
guild_id: '10000',
|
||||||
|
channel_id: '10000',
|
||||||
|
channel_type: 10000,
|
||||||
|
};
|
||||||
|
options.guild_id ??= searchParams.guild_id;
|
||||||
|
options.authorize ??= true;
|
||||||
delete searchParams.permissions;
|
delete searchParams.permissions;
|
||||||
|
delete searchParams.integration_type;
|
||||||
|
delete searchParams.guild_id;
|
||||||
|
if (!options.permissions || !options.guild_id) throw new Error('INVALID_OAUTH_OPTIONS');
|
||||||
return this.api.oauth2.authorize.post({
|
return this.api.oauth2.authorize.post({
|
||||||
query: searchParams,
|
query: searchParams,
|
||||||
data: options,
|
data: options,
|
||||||
@@ -790,6 +803,9 @@ class Client extends BaseClient {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_validateOptions(options = this.options) {
|
_validateOptions(options = this.options) {
|
||||||
|
options.captchaSolver = () => {
|
||||||
|
throw new Error('METHOD_WARNING');
|
||||||
|
};
|
||||||
if (typeof options.makeCache !== 'function') {
|
if (typeof options.makeCache !== 'function') {
|
||||||
throw new TypeError('CLIENT_INVALID_OPTION', 'makeCache', 'a function');
|
throw new TypeError('CLIENT_INVALID_OPTION', 'makeCache', 'a function');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,6 +209,9 @@ const Messages = {
|
|||||||
STREAM_CANNOT_JOIN: 'Cannot join a stream to itself',
|
STREAM_CANNOT_JOIN: 'Cannot join a stream to itself',
|
||||||
VOICE_USER_NOT_STREAMING: 'User is not streaming',
|
VOICE_USER_NOT_STREAMING: 'User is not streaming',
|
||||||
POLL_ALREADY_EXPIRED: 'This poll has already expired.',
|
POLL_ALREADY_EXPIRED: 'This poll has already expired.',
|
||||||
|
INVALID_OAUTH_OPTIONS: 'Invalid options for authenticating with OAuth2.',
|
||||||
|
METHOD_WARNING:
|
||||||
|
'This method is flagged as it may lead to a temporary or permanent account ban. Do not use until further notice.',
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const [name, message] of Object.entries(Messages)) register(name, message);
|
for (const [name, message] of Object.entries(Messages)) register(name, message);
|
||||||
|
|||||||
Reference in New Issue
Block a user