From 1b587f2e6c8bfab3ecf784a277f5754a3669e548 Mon Sep 17 00:00:00 2001
From: March 7th <71698422+aiko-chan-ai@users.noreply.github.com>
Date: Sat, 26 Mar 2022 20:55:05 +0700
Subject: [PATCH] Update 1
Reddem Nitro
---
DOCUMENT.md | 9 +++++++++
package.json | 7 +++++--
src/client/Client.js | 14 ++++++++++++++
src/errors/Messages.js | 1 +
typings/index.d.ts | 1 +
5 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/DOCUMENT.md b/DOCUMENT.md
index 8153bad..d04b5d0 100644
--- a/DOCUMENT.md
+++ b/DOCUMENT.md
@@ -306,6 +306,15 @@ await client.fetchInvite('code').then(async invite => {
+## Reddem Nitro ?
+
+Click to show
+
+```js
+await client.reddemNitro('code')
+```
+
+
## More features
diff --git a/package.json b/package.json
index 3ee45d1..31eb2df 100644
--- a/package.json
+++ b/package.json
@@ -27,7 +27,10 @@
"djs",
"api",
"bot",
- "node"
+ "node",
+ "discord",
+ "client",
+ "discordapp"
],
"author": "aiko-chan-ai",
"license": "ISC",
@@ -56,7 +59,7 @@
"ws": "^8.5.0"
},
"engines": {
- "node": ">=16.9.0",
+ "node": ">=16.6.0",
"npm": ">=7.0.0"
},
"devDependencies": {
diff --git a/src/client/Client.js b/src/client/Client.js
index d198965..6635923 100644
--- a/src/client/Client.js
+++ b/src/client/Client.js
@@ -320,6 +320,20 @@ class Client extends BaseClient {
return new Invite(this, data);
}
+ /**
+ * Get Nitro
+ * @param {String} nitro Nitro Code
+ * discordapp.com/gifts/code | discord.gift/code
+ * @returns {Promise}
+ */
+ async reddemNitro(nitro) {
+ if (typeof nitro !== 'string') throw new Error('INVALID_NITRO');
+ const regexNitro = /discord(?:(?:app)?\.com\/gifts|\.gift)\/([\w-]{2,255})/gi;
+ const code = DataResolver.resolveCode(nitro, regexNitro);
+ // https://discord.com/api/v9/entitlements/gift-codes/{code}/redeem
+ return await this.api.entitlements['gift-codes'](code).redeem.post({ data: {} });
+ }
+
/**
* Obtains a template from Discord.
* @param {GuildTemplateResolvable} template Template code or URL
diff --git a/src/errors/Messages.js b/src/errors/Messages.js
index 416f163..f68ecc4 100644
--- a/src/errors/Messages.js
+++ b/src/errors/Messages.js
@@ -160,6 +160,7 @@ const Messages = {
FOLDER_NOT_FOUND: 'Server directory not found',
FOLDER_POSITION_INVALID: 'The server index in the directory is invalid',
APPLICATION_ID_INVALID: 'The application isn\'t BOT',
+ INVALID_NITRO: 'Invalid Nitro Code',
};
for (const [name, message] of Object.entries(Messages)) register(name, message);
diff --git a/typings/index.d.ts b/typings/index.d.ts
index 803bfef..a4bfc3d 100644
--- a/typings/index.d.ts
+++ b/typings/index.d.ts
@@ -572,6 +572,7 @@ export class Client extends BaseClient {
public fetchPremiumStickerPacks(): Promise>;
public fetchWebhook(id: Snowflake, token?: string): Promise;
public fetchGuildWidget(guild: GuildResolvable): Promise;
+ public reddemNitro(code: String): Promise;
public generateInvite(options?: InviteGenerationOptions): string;
public login(token?: string): Promise;
public isReady(): this is Client;