discordthings-api 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -30
- package/dist/index.d.ts +57 -0
- package/dist/index.js +97 -0
- package/dist/index.js.map +1 -0
- package/package.json +13 -3
- package/index.js +0 -91
package/README.md
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
# DiscordThings API Wrapper
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/discordthings-api)
|
|
4
|
+
[](https://github.com/wdiscordthings/discordthings-api/blob/master/LICENSE)
|
|
5
|
+
[](https://discord.gg/discordthings)
|
|
6
|
+
|
|
7
|
+
The official Node.js library for interacting with the [DiscordThings.com](https://discordthings.com) API. Efficiently manage your bot's stats, synchronize slash commands, and verify user votes with a modern, promise-based wrapper.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Post Stats**: Keep your bot's server and shard count up to date.
|
|
14
|
+
- **Vote Verification**: Reward your users by checking if they've voted for your bot.
|
|
15
|
+
- **Command Sync**: Push your bot's Slash Commands directly to our platform for better visibility.
|
|
16
|
+
- **Lightweight**: Zero dependencies (only `axios`).
|
|
5
17
|
|
|
6
18
|
## Installation
|
|
7
19
|
|
|
@@ -9,57 +21,92 @@ Easily post bot stats and check user votes.
|
|
|
9
21
|
npm install discordthings-api
|
|
10
22
|
```
|
|
11
23
|
|
|
12
|
-
##
|
|
24
|
+
## Quick Start
|
|
13
25
|
|
|
14
|
-
First,
|
|
26
|
+
First, obtain your **API Token** from your [Developer Profile](https://discordthings.com/dashboard) on DiscordThings.
|
|
15
27
|
|
|
16
28
|
```javascript
|
|
17
29
|
const DiscordThings = require('discordthings-api');
|
|
18
30
|
|
|
19
|
-
// Initialize
|
|
20
|
-
const dthings = new DiscordThings('
|
|
31
|
+
// Initialize the client
|
|
32
|
+
const dthings = new DiscordThings('YOUR_USER_API_TOKEN');
|
|
21
33
|
|
|
22
|
-
const BOT_ID = '
|
|
34
|
+
const BOT_ID = '123456789012345678'; // Your Bot ID
|
|
35
|
+
```
|
|
23
36
|
|
|
24
|
-
|
|
37
|
+
### 1. Update Server Count
|
|
38
|
+
```javascript
|
|
39
|
+
async function updateStats() {
|
|
25
40
|
try {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
console.error('Failed to post stats:', error.message);
|
|
41
|
+
await dthings.postStats(BOT_ID, 1250);
|
|
42
|
+
console.log('Stats updated on DiscordThings!');
|
|
43
|
+
} catch (err) {
|
|
44
|
+
console.error('Error updating stats:', err.message);
|
|
31
45
|
}
|
|
32
46
|
}
|
|
47
|
+
```
|
|
33
48
|
|
|
34
|
-
|
|
49
|
+
### 2. Verify Votes
|
|
50
|
+
```javascript
|
|
51
|
+
async function checkVote(userId) {
|
|
35
52
|
try {
|
|
36
|
-
// Check if a user voted
|
|
37
53
|
const result = await dthings.checkVote(BOT_ID, userId);
|
|
38
54
|
|
|
39
55
|
if (result.voted) {
|
|
40
|
-
console.log(
|
|
41
|
-
console.log(`Next vote allowed at: ${result.nextVote}`);
|
|
56
|
+
console.log('User has voted!');
|
|
42
57
|
} else {
|
|
43
|
-
console.log(
|
|
58
|
+
console.log('User hasn\'t voted in the last 12 hours.');
|
|
44
59
|
}
|
|
45
|
-
} catch (
|
|
46
|
-
console.error('Error checking vote:',
|
|
60
|
+
} catch (err) {
|
|
61
|
+
console.error('Error checking vote:', err.message);
|
|
47
62
|
}
|
|
48
63
|
}
|
|
64
|
+
```
|
|
49
65
|
|
|
50
|
-
|
|
66
|
+
### 3. Sync Slash Commands
|
|
67
|
+
```javascript
|
|
68
|
+
async function syncCommands() {
|
|
69
|
+
const commands = [
|
|
70
|
+
{
|
|
71
|
+
name: 'ping',
|
|
72
|
+
description: 'Check bot latency',
|
|
73
|
+
type: 1 // Chat Input
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'help',
|
|
77
|
+
description: 'Get list of commands',
|
|
78
|
+
options: [{ name: 'cmd', description: 'Command to check', type: 3 }]
|
|
79
|
+
}
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
await dthings.syncCommands(BOT_ID, commands);
|
|
84
|
+
console.log('Commands synced successfully!');
|
|
85
|
+
} catch (err) {
|
|
86
|
+
console.error('Sync failed:', err.message);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
51
89
|
```
|
|
52
90
|
|
|
53
|
-
##
|
|
91
|
+
## API Reference
|
|
54
92
|
|
|
55
|
-
### `
|
|
56
|
-
- `token
|
|
57
|
-
- `options.baseUrl
|
|
93
|
+
### `new DiscordThings(token, [options])`
|
|
94
|
+
- `token` (String): Your personal API Token.
|
|
95
|
+
- `options.baseUrl` (String): Override default API endpoint.
|
|
58
96
|
|
|
59
|
-
### `postStats(botId, serverCount, shardCount
|
|
60
|
-
- Updates the server and shard
|
|
61
|
-
-
|
|
97
|
+
### `postStats(botId, serverCount, [shardCount])`
|
|
98
|
+
- Updates the bot's server and shard presence.
|
|
99
|
+
- Returns `Promise<Object>`.
|
|
62
100
|
|
|
63
101
|
### `checkVote(botId, userId)`
|
|
64
|
-
- Checks
|
|
65
|
-
- Returns
|
|
102
|
+
- Checks for a valid vote cast within the last 12 hours.
|
|
103
|
+
- Returns `Promise<{ voted: Boolean, lastVote: Date, nextVote: Date }>`.
|
|
104
|
+
|
|
105
|
+
### `syncCommands(botId, commands)`
|
|
106
|
+
- Synchronizes your bot's command list with the platform.
|
|
107
|
+
- `commands`: Array of Command Objects (name, description, options, type).
|
|
108
|
+
- Returns `Promise<Object>`.
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
Built with love by the [DiscordThings](https://discordthings.com) Team.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export interface DiscordThingsOptions {
|
|
2
|
+
baseUrl?: string;
|
|
3
|
+
}
|
|
4
|
+
export interface VoteResult {
|
|
5
|
+
voted: boolean;
|
|
6
|
+
lastVote: string | null;
|
|
7
|
+
nextVote: string | null;
|
|
8
|
+
}
|
|
9
|
+
export interface CommandOption {
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
type: number;
|
|
13
|
+
required?: boolean;
|
|
14
|
+
choices?: {
|
|
15
|
+
name: string;
|
|
16
|
+
value: string | number;
|
|
17
|
+
}[];
|
|
18
|
+
options?: CommandOption[];
|
|
19
|
+
}
|
|
20
|
+
export interface Command {
|
|
21
|
+
name: string;
|
|
22
|
+
description: string;
|
|
23
|
+
type?: number;
|
|
24
|
+
options?: CommandOption[];
|
|
25
|
+
}
|
|
26
|
+
export declare class DiscordThings {
|
|
27
|
+
private client;
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} token - Your User API Token
|
|
30
|
+
* @param {DiscordThingsOptions} [options] - Configuration options
|
|
31
|
+
*/
|
|
32
|
+
constructor(token: string, options?: DiscordThingsOptions);
|
|
33
|
+
/**
|
|
34
|
+
* Post bot statistics to DiscordThings
|
|
35
|
+
* @param {string} botId - The ID of the bot
|
|
36
|
+
* @param {number} serverCount - Total number of servers the bot is in
|
|
37
|
+
* @param {number} [shardCount] - Total number of shards (optional)
|
|
38
|
+
* @returns {Promise<any>} API Response
|
|
39
|
+
*/
|
|
40
|
+
postStats(botId: string, serverCount: number, shardCount?: number): Promise<any>;
|
|
41
|
+
/**
|
|
42
|
+
* Check if a user has voted for the bot
|
|
43
|
+
* @param {string} botId - The ID of the bot
|
|
44
|
+
* @param {string} userId - The ID of the user
|
|
45
|
+
* @returns {Promise<VoteResult>} Vote status object
|
|
46
|
+
*/
|
|
47
|
+
checkVote(botId: string, userId: string): Promise<VoteResult | undefined>;
|
|
48
|
+
/**
|
|
49
|
+
* Sync commands for the bot
|
|
50
|
+
* @param {string} botId - The ID of the bot
|
|
51
|
+
* @param {Command[]} commands - Array of command objects
|
|
52
|
+
* @returns {Promise<any>} API Response
|
|
53
|
+
*/
|
|
54
|
+
syncCommands(botId: string, commands: Command[]): Promise<any>;
|
|
55
|
+
private _handleError;
|
|
56
|
+
}
|
|
57
|
+
export default DiscordThings;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DiscordThings = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
class DiscordThings {
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} token - Your User API Token
|
|
11
|
+
* @param {DiscordThingsOptions} [options] - Configuration options
|
|
12
|
+
*/
|
|
13
|
+
constructor(token, options = {}) {
|
|
14
|
+
if (!token)
|
|
15
|
+
throw new Error('API Token is required');
|
|
16
|
+
this.client = axios_1.default.create({
|
|
17
|
+
baseURL: options.baseUrl || 'https://discordthings.com/api',
|
|
18
|
+
headers: {
|
|
19
|
+
'Authorization': token,
|
|
20
|
+
'Content-Type': 'application/json'
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Post bot statistics to DiscordThings
|
|
26
|
+
* @param {string} botId - The ID of the bot
|
|
27
|
+
* @param {number} serverCount - Total number of servers the bot is in
|
|
28
|
+
* @param {number} [shardCount] - Total number of shards (optional)
|
|
29
|
+
* @returns {Promise<any>} API Response
|
|
30
|
+
*/
|
|
31
|
+
async postStats(botId, serverCount, shardCount) {
|
|
32
|
+
if (!botId || serverCount === undefined)
|
|
33
|
+
throw new Error('Bot ID and server count are required');
|
|
34
|
+
try {
|
|
35
|
+
const response = await this.client.post(`/bots/${botId}/stats`, {
|
|
36
|
+
server_count: serverCount,
|
|
37
|
+
shard_count: shardCount
|
|
38
|
+
});
|
|
39
|
+
return response.data;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
this._handleError(error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if a user has voted for the bot
|
|
47
|
+
* @param {string} botId - The ID of the bot
|
|
48
|
+
* @param {string} userId - The ID of the user
|
|
49
|
+
* @returns {Promise<VoteResult>} Vote status object
|
|
50
|
+
*/
|
|
51
|
+
async checkVote(botId, userId) {
|
|
52
|
+
if (!botId || !userId)
|
|
53
|
+
throw new Error('Bot ID and User ID are required');
|
|
54
|
+
try {
|
|
55
|
+
const response = await this.client.get(`/bots/${botId}/check-vote`, {
|
|
56
|
+
params: { userId }
|
|
57
|
+
});
|
|
58
|
+
return response.data;
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
this._handleError(error);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Sync commands for the bot
|
|
66
|
+
* @param {string} botId - The ID of the bot
|
|
67
|
+
* @param {Command[]} commands - Array of command objects
|
|
68
|
+
* @returns {Promise<any>} API Response
|
|
69
|
+
*/
|
|
70
|
+
async syncCommands(botId, commands) {
|
|
71
|
+
if (!botId || !Array.isArray(commands))
|
|
72
|
+
throw new Error('Bot ID and commands array are required');
|
|
73
|
+
try {
|
|
74
|
+
const response = await this.client.post(`/bots/${botId}/commands`, {
|
|
75
|
+
commands
|
|
76
|
+
});
|
|
77
|
+
return response.data;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
this._handleError(error);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
_handleError(error) {
|
|
84
|
+
if (axios_1.default.isAxiosError(error) && error.response) {
|
|
85
|
+
throw new Error(`API Error [${error.response.status}]: ${error.response.data.error || error.response.statusText}`);
|
|
86
|
+
}
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.DiscordThings = DiscordThings;
|
|
91
|
+
// Support CommonJS require and ES imports
|
|
92
|
+
exports.default = DiscordThings;
|
|
93
|
+
module.exports = DiscordThings;
|
|
94
|
+
// To maintain compatibility with the previous require('discordthings-api') pattern
|
|
95
|
+
module.exports.default = DiscordThings;
|
|
96
|
+
module.exports.DiscordThings = DiscordThings;
|
|
97
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "discordthings-api",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Official API Wrapper for DiscordThings.com",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
6
10
|
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"prepublishOnly": "npm run build",
|
|
7
13
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
14
|
},
|
|
9
15
|
"keywords": [
|
|
@@ -21,6 +27,10 @@
|
|
|
21
27
|
},
|
|
22
28
|
"repository": {
|
|
23
29
|
"type": "git",
|
|
24
|
-
"url": "https://github.com/discordthings
|
|
30
|
+
"url": "https://github.com/wdiscordthings/discordthings-api.git"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^25.0.3",
|
|
34
|
+
"typescript": "^5.9.3"
|
|
25
35
|
}
|
|
26
36
|
}
|
package/index.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
const axios = require('axios');
|
|
2
|
-
|
|
3
|
-
class DiscordThings {
|
|
4
|
-
/**
|
|
5
|
-
* @param {string} token - Your Bot's API Token (from User Profile)
|
|
6
|
-
* @param {Object} options - Optional settings
|
|
7
|
-
* @param {string} [options.baseUrl='https://discordthings.com/api'] - API Base URL
|
|
8
|
-
*/
|
|
9
|
-
constructor(token, options = {}) {
|
|
10
|
-
if (!token) throw new Error('A valid API Token is required');
|
|
11
|
-
|
|
12
|
-
this.token = token;
|
|
13
|
-
this.baseUrl = options.baseUrl || 'https://discordthings.com/api';
|
|
14
|
-
|
|
15
|
-
this.client = axios.create({
|
|
16
|
-
baseURL: this.baseUrl,
|
|
17
|
-
headers: {
|
|
18
|
-
'Content-Type': 'application/json',
|
|
19
|
-
'Authorization': this.token
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Post Server and Shard Count Stats
|
|
26
|
-
* @param {string} botId - The ID of the bot
|
|
27
|
-
* @param {number} serverCount - Total number of servers
|
|
28
|
-
* @param {number} [shardCount=0] - Total number of shards (optional)
|
|
29
|
-
* @returns {Promise<Object>} API Response
|
|
30
|
-
*/
|
|
31
|
-
async postStats(botId, serverCount, shardCount = 0) {
|
|
32
|
-
if (!botId) throw new Error('Bot ID is required');
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
const response = await this.client.post(`/bots/${botId}/stats`, {
|
|
36
|
-
server_count: serverCount,
|
|
37
|
-
shard_count: shardCount
|
|
38
|
-
});
|
|
39
|
-
return response.data;
|
|
40
|
-
} catch (error) {
|
|
41
|
-
this._handleError(error);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Check if a user has voted for a bot
|
|
47
|
-
* @param {string} botId - The ID of the bot
|
|
48
|
-
* @param {string} userId - The ID of the user to check
|
|
49
|
-
* @returns {Promise<Object>} { voted: boolean, lastVote: Date, nextVote: Date }
|
|
50
|
-
*/
|
|
51
|
-
async checkVote(botId, userId) {
|
|
52
|
-
if (!botId || !userId) throw new Error('Bot ID and User ID are required');
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
const response = await this.client.get(`/bots/${botId}/check-vote`, {
|
|
56
|
-
params: { userId }
|
|
57
|
-
});
|
|
58
|
-
return response.data;
|
|
59
|
-
} catch (error) {
|
|
60
|
-
this._handleError(error);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Sync commands for the bot
|
|
66
|
-
* @param {string} botId - The ID of the bot
|
|
67
|
-
* @param {Array} commands - Array of command objects
|
|
68
|
-
* @returns {Promise<Object>} API Response
|
|
69
|
-
*/
|
|
70
|
-
async syncCommands(botId, commands) {
|
|
71
|
-
if (!botId || !Array.isArray(commands)) throw new Error('Bot ID and commands array are required');
|
|
72
|
-
|
|
73
|
-
try {
|
|
74
|
-
const response = await this.client.post(`/bots/${botId}/commands`, {
|
|
75
|
-
commands
|
|
76
|
-
});
|
|
77
|
-
return response.data;
|
|
78
|
-
} catch (error) {
|
|
79
|
-
this._handleError(error);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
_handleError(error) {
|
|
84
|
-
if (error.response) {
|
|
85
|
-
throw new Error(`API Error [${error.response.status}]: ${error.response.data.error || error.response.statusText}`);
|
|
86
|
-
}
|
|
87
|
-
throw error;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
module.exports = DiscordThings;
|