Ana içeriğe atla

Yaygın Kullanım Alanları

Temel Kurulum#

Kütüphaneyi kullanmaya nasıl başlayacağımızı ve şu anda kullandığınız kodla nasıl birleştireceğimizi öğreneceğiz.

Discord client kütüphanesi olarak discord.js kullanıcağız.

Kurulum#

Kullanacağımız çok basit bir discord bot kurulumu.

app.ts
import { Client } from 'discord.js'
const client = new Client()
client.on('ready', () => console.log("Hazırım o7"))
client.login('DISCORD_TOKEN')

Client Oluşturma#

Artık temel bir kuruluma sahip olduğumuza göre, dclist ile etkileşime başlamak için GatewayClient'imizi oluşturabiliriz

app.ts
import { Client } from 'discord.js'
import { GatewayClient } from '@dclist/sdk'
const client = new Client()
const dclClient = new GatewayClient({
token: 'DCLIST_TOKEN'
})
client.on('ready', () => console.log("Hazırım o7"))
client.login('DISCORD_TOKEN')

Oylayan-Özel Komutlar#

Sadece oyverenlerin kullanabilecekleri komutlara sahip olabilirsiniz. Resmi sdk'i kullanarak bunu kolayca yapabilirsiniz. Aşağıdaki GatewayClient'ın #isUserVoted yöntemini kullanmak için çoook basit bir örnek.

app.ts
import { Client } from 'discord.js'
import { GatewayClient } from '@dclist/sdk'
const client = new Client()
const dclClient = new GatewayClient({
token: 'DCLIST_TOKEN'
})
client.on('ready', () => console.log("Hazırım o7"))
client.on('message', async (message) => {
if (message.author.bot) return
if (message.content.startsWith('!voterOnly')) {
const userVoted = await dclClient.isUserVoted(message.author.id)
if (!userVoted) {
message.reply(`bu komudu kullanmak için oy vermeniz gerekmektedir. Burdan oy verebilirsiniz : https://dclist.net/bots/${client.user.id}/vote`)
return
}
}
// Burda Havalı Şeyler Yapın
})
client.login('DISCORD_TOKEN')

Etkinliklere Abone Olun#

Dclist gerçek zamanlı olayları işlemek için biraz farklı bir sistem kullanıyor. Sadece yeni oy etkinliği için express web sunucusu oluşturmak yerine, webspcket kullanarak direk sunucuya bağlanıyor. Bu, etkinlikleri kullanmak için başka herhangi bir ayar yapmanıza gerek yok demek. Fikir vermesi için çoook basit bir etkinlik kaydedici kodu.

Etkinlik Istemek#

Öncelikle, hangi etkinliklerden haber almak istediğinizi sunucuya söylemeniz gerekir. Daha sonra sunucu size gerçek zamanlı olarak ektinlikleri göndermeye başlayacaktır.

app.ts
import { Client } from 'discord.js'
import { GatewayClient, SubscriptionsTopicsEnum } from '@dclist/sdk'
const client = new Client()
const dclClient = new GatewayClient({
token: 'DCLIST_TOKEN'
})
// Bu metod sync bir metoddur. Async/await kullanmanıza gerek yok
dclClient.subscribeTo([SubscriptionsTopicsEnum.NEW_VOTE])
client.on('ready', () => console.log("Hazırım o7"))
client.on('message', async (message) => {
if (message.author.bot) return
if (message.content.startsWith('!voterOnly')) {
const userVoted = await dclClient.isUserVoted(message.author.id)
if (!userVoted) {
message.reply(`bu komudu kullanmak için oy vermeniz gerekmektedir. Burdan oy verebilirsiniz : https://dclist.net/bots/${client.user.id}/vote`)
return
}
}
// Burda Havalı Şeyler Yapın
})
client.login('DISCORD_TOKEN')

Etkinlikleri İşlemek#

Gerçek zamanlı bir etkinlik alındığında, GatewayClient alınan olayın türüyle aynı adlı bir olay yayar.

app.ts
import { Client } from 'discord.js'
import { GatewayClient, SubscriptionsTopicsEnum } from '@dclist/sdk'
const client = new Client()
const dclClient = new GatewayClient({
token: 'DCLIST_TOKEN'
})
// Bu metod sync bir metoddur. Async/await kullanmanıza gerek yok
dclClient.subscribeTo([SubscriptionsTopicsEnum.NEW_VOTE])
dclCLient.on(SubscriptionsTopicsEnum.NEW_VOTE, (vote) => {
const logChannel = client.channels.cache.get('LOG_CHANNEL_ID') as TextChannel
logChannel.send(`Oyun için teşekkurler <@${vote.payload.user.id}> .`)
})
client.on('ready', () => console.log("Hazırım o7"))
client.on('message', async (message) => {
if (message.author.bot) return
if (message.content.startsWith('!voterOnly')) {
const userVoted = await dclClient.isUserVoted(message.author.id)
if (!userVoted) {
message.reply(`bu komudu kullanmak için oy vermeniz gerekmektedir. Burdan oy verebilirsiniz : https://dclist.net/bots/${client.user.id}/vote`)
return
}
}
// Burda Havalı Şeyler Yapın
})
client.login('DISCORD_TOKEN')

AutoPoster Kullanımı#

Kendi sitemizde botunuz sunucu, kullanıcısını vb. sayılarını göstermemiz ve sizin için botunuzun büyüme grafiğini takip etmek için bize bazı veriler göndermeiz gerekli. Bunu kodunuzdan sadece birkaç satır değiştirerek yapabilirsiniz. İşle shardlanmış yada tek başın çalışan botlar için örnek kodlar.

Tek Çalışan Bot Kurulumu#

app.ts
import { Client } from 'discord.js'
import { GatewayClient } from '@dclist/sdk'
const client = new Client()
const dclClient = new GatewayClient({
token: 'DCLIST_TOKEN',
// !ÖNEMLİ!
client: client,
enablePoster: true,
// !ÖNEMLİ!
})
client.on('ready', () => console.log("I'm ready sir o7"))
client.login('DISCORD_TOKEN')

Shardlı Bot Kurulumu#

Shard Manager Dosyası#

sharder.ts
import { ShardingManager } from 'discord.js'
import { GatewayClient } from '@dclist/sdk'
const shardManager = new ShardingManager(...)
const dclClient = new GatewayClient({
token: 'DCLIST_TOKEN',
// !ÖNEMLİ!
client: shardManager,
enablePoster: true,
// !ÖNEMLİ!
})
client.on('ready', () => console.log("I'm ready sir o7"))
shardManager.spawn()

Shard Client Dosyası#

shard.ts
import { Client } from 'discord.js'
import { GatewayClient } from '@dclist/sdk'
const client = new Client()
const dclClient = new GatewayClient({
token: 'DCLIST_TOKEN',
// Buraya client yada enablePoster parametrelerini girmeyin
})
client.on('ready', () => console.log("Hazırım o7"))
client.login('DISCORD_TOKEN')