felix-wrapper v1.2.0
This is a wrapper for the API of Felix, a Discord bot
This wrapper covers 100% of Felix's API and will be updated at the same time as Felix's API is
Tables of contents
Constructor Methods Error Handling
Constructor
const FelixWrapper = require("felix-wrapper");
let wrapper = new FelixWrapper({
url: "",
token: "",
timeout: 42,
autoConversion: false
});| Property | Type | Description |
|---|---|---|
| url | String | Required. The base url of the domain to request to |
| token | String | Optional. The token (private or public), optional but required for almost all endpoints |
| timeout | Number | Optional. The time in ms before requests should be aborted, default is 6000 |
| autoConversion | Boolean | Optional. Whether arrays should be converted to enhanced maps, default is true |
Methods
wrapper.status()
Returns: A boolean based on whether Felix's API is up or not
wrapper.getUserData(user, options)
Returns: The user object/array of user objects
| Params | Type | Description |
|---|---|---|
| user | String OR Array | Required. The user ID or an array of IDs of the user(s) to fetch |
| options | Object | Optional. An object of options |
| options.timeout | Number | Optional. The time in ms before this request should be aborted, default is wrapper.timeout |
wrapper.postUserData(user, options)
Restricted to private tokens
Returns: The posted user object if the operation is successful, otherwise reject an error
| Params | Type | Description |
|---|---|---|
| user | Object | Required. The user object to POST, will update or create a new database entry |
| options | Object | Optional. An object of options |
| options.timeout | Number | Optional. The time in ms before this request should be aborted, default is wrapper.timeout |
wrapper.getGuildData(guild, options)
Returns: The guild object/array of guild objects
| Params | Type | Description |
|---|---|---|
| guild | String OR Array | Required. The guild ID or an array of IDs of the guild(s) to fetch |
| options | Object | Optional. An object of options |
| options.timeout | Number | Optional. The time in ms before this request should be aborted, default is wrapper.timeout |
wrapper.postGuildData(guild, options)
Restricted to private tokens
Returns: The posted guild object if the operation is successful, otherwise reject an error
| Params | Type | Description |
|---|---|---|
| guild | Object | Required. The guild object to POST, will update or create a new database entry |
| options | Object | Optional. An object of options |
| options.timeout | Number | Optional. The time in ms before this request should be aborted, default is wrapper.timeout |
wrapper.fetchClientValue(value)
Restricted to private tokens
Returns: The value
| Params | Type | Description |
|---|---|---|
| value | String | Required. The value to fetch, this will be interpreted as a property name of the client object |
Error Handling
As of update 1.2.0, errors have been standardized and now follow a logical scheme.
All errors are rejected and the rejection structure is the following:
{
code: 403,
message: 'Forbidden',
data: 'Forbidden'
}| Props | Type | Description |
|---|---|---|
| code | Number | The HTTP error code returned by the server or an appropriate equivalent regarding the error |
| message | String | The description of the HTTP error code |
| data | * | The error the server returned, this can be a simple "Forbidden" to an array of invalid data the server encountered in a post request |
Errors code you are the most likely to encounter:
| Code | Message | Description |
|---|---|---|
| 400 | Bad Request | The object sent along with a method like postUser() is invalid |
| 403 | Forbidden | You did not specified a token, the token is invalid or you have a public token and tried to use a method restricted to private tokens |
| 408 | Request Timeout | The server did not answered in the time set in the constructor, or in the 6000 default ms |
| 429 | Too Much Requests | You use a public token and reached the rate-limit |