Added Simplified Intents, and an example
This commit is contained in:
parent
5fa0138063
commit
f6eaa739ab
4 changed files with 117 additions and 43 deletions
39
examples/ping.ts
Normal file
39
examples/ping.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
import { Client, Message, Intents } from '../mod.ts'
|
||||
|
||||
const client = new Client();
|
||||
|
||||
client.on("ready", () => {
|
||||
console.log(`Logged in as ${client.user?.tag}!`);
|
||||
});
|
||||
|
||||
client.on("messageCreate", (msg: Message) => {
|
||||
if(msg.content === "!ping") {
|
||||
console.log("Command Used: Ping");
|
||||
msg.reply("pong!");
|
||||
}
|
||||
});
|
||||
|
||||
console.log("discord.deno - ping example");
|
||||
|
||||
const token = prompt("Input Bot Token:");
|
||||
if(!token) {
|
||||
console.log("No token provided");
|
||||
Deno.exit();
|
||||
}
|
||||
|
||||
const intents = prompt("Input Intents (0 = All, 1 = Presence, 2 = Server Members):");
|
||||
if(!intents || !["0", "1", "2"].includes(intents)) {
|
||||
console.log("No intents provided");
|
||||
Deno.exit();
|
||||
}
|
||||
|
||||
let ints;
|
||||
if(intents == "0") {
|
||||
ints = Intents.All;
|
||||
} else if(intents == "1") {
|
||||
ints = Intents.Presence;
|
||||
} else {
|
||||
ints = Intents.GuildMembers;
|
||||
}
|
||||
|
||||
client.connect(token, ints);
|
3
mod.ts
3
mod.ts
|
@ -52,4 +52,5 @@ export * from './src/types/template.ts'
|
|||
export * from './src/types/user.ts'
|
||||
export * from './src/types/voice.ts'
|
||||
export * from './src/types/webhook.ts'
|
||||
export * from './src/utils/collection.ts'
|
||||
export * from './src/utils/collection.ts'
|
||||
export * from './src/utils/intents.ts'
|
|
@ -1,39 +1,25 @@
|
|||
// import { Client } from '../models/client.ts'
|
||||
// import { GatewayIntents } from '../types/gateway.ts'
|
||||
import { Client, GuildTextChannel, GatewayIntents, Message, DefaultCacheAdapter, ClientPresence, Member, Role, GuildChannel, TextChannel, Embed, Guild } from '../../mod.ts';
|
||||
import { Intents } from "../utils/intents.ts";
|
||||
import { TOKEN } from './config.ts'
|
||||
// import { Message } from "../structures/message.ts"
|
||||
// import { DefaultCacheAdapter } from "../models/cacheAdapter.ts"
|
||||
// import { ClientPresence } from "../structures/presence.ts"
|
||||
// import { Member } from "../structures/member.ts"
|
||||
// import { Role } from "../structures/role.ts"
|
||||
// import { GuildChannel } from "../managers/guildChannels.ts"
|
||||
// import { TextChannel } from "../structures/textChannel.ts"
|
||||
// import { Embed } from "../structures/embed.ts"
|
||||
// import { Guild } from "../structures/guild.ts"
|
||||
import { Client, GatewayIntents, Message, DefaultCacheAdapter, ClientPresence, Member, Role, GuildChannel, TextChannel, Embed, Guild } from '../../mod.ts';
|
||||
|
||||
const bot = new Client({
|
||||
const client = new Client({
|
||||
presence: new ClientPresence({
|
||||
activity: {
|
||||
name: "Testing",
|
||||
name: "Pokémon Sword",
|
||||
type: 'COMPETING'
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
bot.setAdapter(new DefaultCacheAdapter(bot))
|
||||
client.setAdapter(new DefaultCacheAdapter(client))
|
||||
|
||||
bot.on('ready', () => {
|
||||
console.log(`[Login] Logged in as ${bot.user?.tag}!`)
|
||||
bot.setPresence({
|
||||
name: "Test - Ready",
|
||||
type: 'COMPETING'
|
||||
})
|
||||
client.on('ready', () => {
|
||||
console.log(`[Login] Logged in as ${client.user?.tag}!`)
|
||||
})
|
||||
|
||||
bot.on('debug', console.log)
|
||||
client.on('debug', console.log)
|
||||
|
||||
bot.on('channelPinsUpdate', (before: TextChannel, after: TextChannel) => {
|
||||
client.on('channelPinsUpdate', (before: TextChannel, after: TextChannel) => {
|
||||
console.log(before.send('', {
|
||||
embed: new Embed({
|
||||
title: 'Test',
|
||||
|
@ -42,10 +28,19 @@ bot.on('channelPinsUpdate', (before: TextChannel, after: TextChannel) => {
|
|||
}))
|
||||
})
|
||||
|
||||
bot.on('messageCreate', async (msg: Message) => {
|
||||
client.on('channelUpdate', (before: GuildTextChannel, after: GuildTextChannel) => {
|
||||
console.log(before.send('', {
|
||||
embed: new Embed({
|
||||
title: 'Channel Update',
|
||||
description: `Name Before: ${before.name}\nName After: ${after.name}`
|
||||
})
|
||||
}))
|
||||
})
|
||||
|
||||
client.on('messageCreate', async (msg: Message) => {
|
||||
if (msg.author.bot === true) return
|
||||
if (msg.content === "!ping") {
|
||||
msg.reply(`Pong! Ping: ${bot.ping}ms`)
|
||||
msg.reply(`Pong! Ping: ${client.ping}ms`)
|
||||
} else if (msg.content === "!members") {
|
||||
const col = await msg.guild?.members.collection()
|
||||
const data = col?.array().map((c: Member, i: number) => {
|
||||
|
@ -72,20 +67,4 @@ bot.on('messageCreate', async (msg: Message) => {
|
|||
}
|
||||
})
|
||||
|
||||
bot.connect(TOKEN, [
|
||||
GatewayIntents.GUILD_MEMBERS,
|
||||
GatewayIntents.GUILD_PRESENCES,
|
||||
GatewayIntents.GUILD_MESSAGES,
|
||||
GatewayIntents.DIRECT_MESSAGES,
|
||||
GatewayIntents.DIRECT_MESSAGE_REACTIONS,
|
||||
GatewayIntents.DIRECT_MESSAGE_TYPING,
|
||||
GatewayIntents.GUILDS,
|
||||
GatewayIntents.GUILD_BANS,
|
||||
GatewayIntents.GUILD_EMOJIS,
|
||||
GatewayIntents.GUILD_INTEGRATIONS,
|
||||
GatewayIntents.GUILD_INVITES,
|
||||
GatewayIntents.GUILD_MESSAGE_REACTIONS,
|
||||
GatewayIntents.GUILD_MESSAGE_TYPING,
|
||||
GatewayIntents.GUILD_VOICE_STATES,
|
||||
GatewayIntents.GUILD_WEBHOOKS
|
||||
])
|
||||
client.connect(TOKEN, Intents.All)
|
||||
|
|
55
src/utils/intents.ts
Normal file
55
src/utils/intents.ts
Normal file
|
@ -0,0 +1,55 @@
|
|||
import { GatewayIntents } from "../types/gateway.ts";
|
||||
|
||||
export class Intents {
|
||||
static All: number[] = [
|
||||
GatewayIntents.GUILD_MEMBERS,
|
||||
GatewayIntents.GUILD_PRESENCES,
|
||||
GatewayIntents.GUILD_MESSAGES,
|
||||
GatewayIntents.DIRECT_MESSAGES,
|
||||
GatewayIntents.DIRECT_MESSAGE_REACTIONS,
|
||||
GatewayIntents.DIRECT_MESSAGE_TYPING,
|
||||
GatewayIntents.GUILDS,
|
||||
GatewayIntents.GUILD_BANS,
|
||||
GatewayIntents.GUILD_EMOJIS,
|
||||
GatewayIntents.GUILD_INTEGRATIONS,
|
||||
GatewayIntents.GUILD_INVITES,
|
||||
GatewayIntents.GUILD_MESSAGE_REACTIONS,
|
||||
GatewayIntents.GUILD_MESSAGE_TYPING,
|
||||
GatewayIntents.GUILD_VOICE_STATES,
|
||||
GatewayIntents.GUILD_WEBHOOKS
|
||||
];
|
||||
|
||||
static Presence: number[] = [
|
||||
GatewayIntents.GUILD_PRESENCES,
|
||||
GatewayIntents.GUILD_MESSAGES,
|
||||
GatewayIntents.DIRECT_MESSAGES,
|
||||
GatewayIntents.DIRECT_MESSAGE_REACTIONS,
|
||||
GatewayIntents.DIRECT_MESSAGE_TYPING,
|
||||
GatewayIntents.GUILDS,
|
||||
GatewayIntents.GUILD_BANS,
|
||||
GatewayIntents.GUILD_EMOJIS,
|
||||
GatewayIntents.GUILD_INTEGRATIONS,
|
||||
GatewayIntents.GUILD_INVITES,
|
||||
GatewayIntents.GUILD_MESSAGE_REACTIONS,
|
||||
GatewayIntents.GUILD_MESSAGE_TYPING,
|
||||
GatewayIntents.GUILD_VOICE_STATES,
|
||||
GatewayIntents.GUILD_WEBHOOKS
|
||||
];
|
||||
|
||||
static GuildMembers: number[] = [
|
||||
GatewayIntents.GUILD_MEMBERS,
|
||||
GatewayIntents.GUILD_MESSAGES,
|
||||
GatewayIntents.DIRECT_MESSAGES,
|
||||
GatewayIntents.DIRECT_MESSAGE_REACTIONS,
|
||||
GatewayIntents.DIRECT_MESSAGE_TYPING,
|
||||
GatewayIntents.GUILDS,
|
||||
GatewayIntents.GUILD_BANS,
|
||||
GatewayIntents.GUILD_EMOJIS,
|
||||
GatewayIntents.GUILD_INTEGRATIONS,
|
||||
GatewayIntents.GUILD_INVITES,
|
||||
GatewayIntents.GUILD_MESSAGE_REACTIONS,
|
||||
GatewayIntents.GUILD_MESSAGE_TYPING,
|
||||
GatewayIntents.GUILD_VOICE_STATES,
|
||||
GatewayIntents.GUILD_WEBHOOKS
|
||||
];
|
||||
}
|
Loading…
Reference in a new issue