Skip to main content

Gateway Client

What is GatewayClient#

GatewayClient is the class allows you to interact with dclist's graphql API

Constructor#

Constructor method of GatewayClient accepts an object as first parameter. Properties of accepted object :

PropertyTypeIs OptionalDescription
tokenstringFalseToken obtained from website
client*TrueYour library's client object
enablePosterbooleanTrueDefault false. Set true if you want to post your bot's stats automatically
import { GatewayClient } from '@dclist/sdk'
const dclClient = new GatewayClient({
token: 'YOUR_TOKEN_HERE'
})

Methods#

getBotById#

Fetches the bot with given id.

PropertyTypeIs OptionalDescription
botIdstringFalseDiscord id of the bot
fieldSelectorFieldSelectorTrueCustom FieldSelector for advanced usage
ReturnsPromise BotReturns a promise which will resolve an Bot object

Fetch bot normally#

const bot = await dclClient.getBotById('690214077490004030')
console.log(bot)
// Console Output :
{
id: '690214077490004030',
username: 'Techno Bot',
discriminator: '1197',
avatar: 'ffa1ff0c8616ef03c9a87871a654ae3e',
stats: { ... },
prefix: 't!',
prefixType: 'DYNAMIC',
website: 'https://technobot.xyz/',
github: null,
tags: [ 'turkish', 'game', 'dashboard' ]
}

Fetch bot with custom FieldSelector#

import { FieldSelector, Bot } from '@dclist/sdk'
const customFieldSelector = new FieldSelector<Bot>({
// Change here with your need
id: 1,
username: 1,
avatar: 1,
})
const bot = await dclClient.getBotById('690214077490004030', customFieldSelector)
console.log(bot)
// Console Output :
{
id: '690214077490004030',
username: 'Techno Bot',
avatar: 'ffa1ff0c8616ef03c9a87871a654ae3e'
}

getUserById#

Fetches the user with given id.

PropertyTypeIs OptionalDescription
userIdstringFalseDiscord id of the user
fieldSelectorFieldSelectorTrueCustom FieldSelector for advanced usage
ReturnsPromise UserReturns a promise which will resolve an User object

Fetch user normally#

const user = await dclClient.getUserById('685124491466113096')
console.log(user)
// Console Output :
{
id: '685124491466113096',
username: 'technoeren',
discriminator: '7608',
avatar: '95d834bd53399f6fe4b9b7fee2dcc38c',
website: 'https://technobot.xyz/',
github: null
}

Fetch user with custom FieldSelector#

import { FieldSelector, User } from '@dclist/sdk'
const customFieldSelector = new FieldSelector<User>({
// Change here with your need
id: 1,
username: 1,
avatar: 1,
})
const user = await dclClient.getUserById('685124491466113096', customFieldSelector)
console.log(user)
// Console Output :
{
id: '685124491466113096',
username: 'technoeren',
avatar: '95d834bd53399f6fe4b9b7fee2dcc38c'
}

isUserVoted#

Checks if user voted to the bot in last 12 hours.

PropertyTypeIs OptionalDescription
userIdstringFalseDiscord id of the user
ReturnsPromise booleanReturns a promise which will resolve a boolean
const isVoted = await dclClient.isUserVoted('685124491466113096')
console.log(isVoted)
// Console Output :
true

getUserComment#

Gets the comment posted by user on your bot

PropertyTypeIs OptionalDescription
userIdstringFalseDiscord id of the user
fieldSelectorFieldSelectorTrueCustom FieldSelector for advanced usage
ReturnsPromise CommentReturns a promise which will resolve an Comment object

Fetch user comment#

const comment = await dclClient.getUserComment('685124491466113096')
console.log(comment)
// Console Output :
{
// Bot who posted comment on
subject: {
id: '690214077490004030',
username: 'Techno Bot',
discriminator: '1197',
avatar: 'ffa1ff0c8616ef03c9a87871a654ae3e',
},
// User who posted comment
author: {
id: '685124491466113096',
username: 'technoeren',
discriminator: '7608',
avatar: 'a0cca1132a472eae99373585c8a784c1'
},
type: 'PARENT',
like: 666,
content: '...'
}

Fetch user comment with custom FieldSelector#

import { FieldSelector, Comment } from '@dclist/sdk'
const customFieldSelector = new FieldSelector<Comment>({
// Change here with your need
author: {
id: 1,
username: 1,
avatar: 1,
},
like: 1,
content: 1,
})
const comment = await dclClient.getUserComment('685124491466113096', customFieldSelector)
console.log(comment)
// Console Output :
{
author: {
id: '685124491466113096',
username: 'technoeren',
avatar: 'a0cca1132a472eae99373585c8a784c1'
},
like: 666,
content: '...'
}

subscribeTo#

Subscribes to given topics. Read more about events in dedicated guide.

PropertyTypeIs OptionalDescription
topicsstring arrayFalseList of topics you want to subscribe
fieldSelectorFieldSelector objectTrueCustom FieldSelectors for each topics to advanced usage
Returnsarray stringList of subscribed topics

Subscribe to new vote event#

import { SubscriptionsTopicsEnum } from '@dclist/sdk'
const subTopics = await dclClient.subscribeTo([SubscriptionsTopicsEnum.NEW_VOTE])
console.log(subTopics)
// Console Output :
[ 'SDK_NEW_VOTE' ]