Abheek Dhawan
2 years ago
19 changed files with 1340 additions and 1085 deletions
@ -1,16 +1,18 @@ |
|||||
import { SlashCommandBuilder } from '@discordjs/builders'; |
import { SlashCommandBuilder } from "@discordjs/builders"; |
||||
import { MessageEmbed, CommandInteraction } from 'discord.js'; |
import { MessageEmbed, CommandInteraction } from "discord.js"; |
||||
|
|
||||
export const data = new SlashCommandBuilder() |
export const data = new SlashCommandBuilder() |
||||
.setName('help') |
.setName("help") |
||||
.setDescription('Replies with a help message explaining what the bot can do'); |
.setDescription("Replies with a help message explaining what the bot can do"); |
||||
|
|
||||
export async function execute(interaction: CommandInteraction) { |
export async function execute(interaction: CommandInteraction) { |
||||
await interaction.deferReply(); |
await interaction.deferReply(); |
||||
await interaction.deferReply(); |
await interaction.deferReply(); |
||||
|
|
||||
const helpEmbed = new MessageEmbed() |
const helpEmbed = new MessageEmbed() |
||||
.setDescription('AwesomeSciBo has migrated to using slash commands! You can take a look at the different commands by typing `/` and clicking on the AwesomeSciBo icon.') |
.setDescription( |
||||
.setColor('#ffffff'); |
"AwesomeSciBo has migrated to using slash commands! You can take a look at the different commands by typing `/` and clicking on the AwesomeSciBo icon." |
||||
|
) |
||||
|
.setColor("#ffffff"); |
||||
interaction.followUp({ embeds: [helpEmbed] }); |
interaction.followUp({ embeds: [helpEmbed] }); |
||||
} |
} |
@ -1,16 +1,17 @@ |
|||||
import * as db from '../helpers/db'; |
import * as db from "../helpers/db"; |
||||
import { mongoUri } from '../helpers/env'; |
import { mongoUri } from "../helpers/env"; |
||||
import log from '../helpers/log'; |
import log from "../helpers/log"; |
||||
|
|
||||
export const name = 'ready'; |
export const name = "ready"; |
||||
|
|
||||
export const once = true; |
export const once = true; |
||||
|
|
||||
export async function execute(client) { |
export async function execute(client) { |
||||
await db.connect(mongoUri); |
await db.connect(mongoUri); |
||||
log({ logger: 'status', content: `Logged in as ${client.user.tag}!`, level: 'info' }); |
log({ |
||||
client.user.setActivity( |
logger: "status", |
||||
'for /help', |
content: `Logged in as ${client.user.tag}!`, |
||||
{ type: 'WATCHING' }, |
level: "info", |
||||
); |
}); |
||||
|
client.user.setActivity("for /help", { type: "WATCHING" }); |
||||
} |
} |
||||
|
@ -1,6 +1,7 @@ |
|||||
import 'dotenv/config'; |
import "dotenv/config"; |
||||
|
|
||||
export const clientId = process.env.CLIENT_ID || ''; |
export const clientId = process.env.CLIENT_ID || ""; |
||||
export const testingGuild = process.env.TESTING_GUILD || ''; |
export const testingGuild = process.env.TESTING_GUILD || ""; |
||||
export const token = process.env.TOKEN || ''; |
export const token = process.env.TOKEN || ""; |
||||
export const mongoUri = process.env.MONGO_URI = 'mongodb://mongo:27017/AWESOME'; |
export const mongoUri = (process.env.MONGO_URI = |
||||
|
"mongodb://mongo:27017/AWESOME"); |
||||
|
@ -1,87 +1,113 @@ |
|||||
import { CommandInteraction, Message, MessageActionRow, MessageButton, MessageEmbed } from 'discord.js'; |
import { |
||||
|
CommandInteraction, |
||||
|
Message, |
||||
|
MessageActionRow, |
||||
|
MessageButton, |
||||
|
MessageEmbed, |
||||
|
} from "discord.js"; |
||||
|
|
||||
export async function paginateMessage(message: Message, embeds: MessageEmbed[]) { |
export async function paginateMessage( |
||||
|
message: Message, |
||||
|
embeds: MessageEmbed[] |
||||
|
) { |
||||
let index = 0; |
let index = 0; |
||||
|
|
||||
const row = new MessageActionRow; |
const row = new MessageActionRow(); |
||||
row.addComponents( |
row.addComponents( |
||||
new MessageButton() |
new MessageButton() |
||||
.setCustomId('paginator-left') |
.setCustomId("paginator-left") |
||||
.setEmoji('868552005977788466') |
.setEmoji("868552005977788466") |
||||
.setStyle('SECONDARY'), |
.setStyle("SECONDARY"), |
||||
new MessageButton() |
new MessageButton() |
||||
.setCustomId('paginator-right') |
.setCustomId("paginator-right") |
||||
.setEmoji('868551772887711754') |
.setEmoji("868551772887711754") |
||||
.setStyle('SECONDARY') |
.setStyle("SECONDARY") |
||||
); |
); |
||||
|
|
||||
await message.reply({ content: `Page 1 of ${embeds.length}:`, embeds: [embeds[index]], components: [row] }) |
await message |
||||
.then(async paginatorMessage => { |
.reply({ |
||||
const filter = m => m.author.id === message.author.id; |
content: `Page 1 of ${embeds.length}:`, |
||||
|
embeds: [embeds[index]], |
||||
|
components: [row], |
||||
|
}) |
||||
|
.then(async (paginatorMessage) => { |
||||
|
const filter = (m) => m.author.id === message.author.id; |
||||
|
|
||||
const paginatorCollector = paginatorMessage.createMessageComponentCollector({ |
const paginatorCollector = |
||||
componentType: 'BUTTON', |
paginatorMessage.createMessageComponentCollector({ |
||||
|
componentType: "BUTTON", |
||||
filter: filter, |
filter: filter, |
||||
}); |
}); |
||||
|
|
||||
paginatorCollector.on('collect', async i => { |
paginatorCollector.on("collect", async (i) => { |
||||
switch (i.customId) { |
switch (i.customId) { |
||||
case 'paginator-left': |
case "paginator-left": |
||||
index--; |
index--; |
||||
if (index < 0) index = embeds.length - 1; |
if (index < 0) index = embeds.length - 1; |
||||
break; |
break; |
||||
case 'paginator-right': |
case "paginator-right": |
||||
index++; |
index++; |
||||
if (index > embeds.length - 1) index = 0; |
if (index > embeds.length - 1) index = 0; |
||||
break; |
break; |
||||
} |
} |
||||
paginatorMessage.edit({ content: `Page ${index + 1} of ${embeds.length}:`, embeds: [embeds[index]] }); |
paginatorMessage.edit({ |
||||
|
content: `Page ${index + 1} of ${embeds.length}:`, |
||||
|
embeds: [embeds[index]], |
||||
|
}); |
||||
}); |
}); |
||||
}); |
}); |
||||
} |
} |
||||
|
|
||||
export async function paginateInteraction(interaction: CommandInteraction, embeds: MessageEmbed[]) { |
export async function paginateInteraction( |
||||
|
interaction: CommandInteraction, |
||||
|
embeds: MessageEmbed[] |
||||
|
) { |
||||
let index = 0; |
let index = 0; |
||||
|
|
||||
const row = new MessageActionRow; |
const row = new MessageActionRow(); |
||||
row.addComponents( |
row.addComponents( |
||||
new MessageButton() |
new MessageButton() |
||||
.setCustomId('paginator-left') |
.setCustomId("paginator-left") |
||||
.setEmoji('868552005977788466') |
.setEmoji("868552005977788466") |
||||
.setStyle('SECONDARY'), |
.setStyle("SECONDARY"), |
||||
new MessageButton() |
new MessageButton() |
||||
.setCustomId('paginator-right') |
.setCustomId("paginator-right") |
||||
.setEmoji('868551772887711754') |
.setEmoji("868551772887711754") |
||||
.setStyle('SECONDARY') |
.setStyle("SECONDARY") |
||||
); |
); |
||||
|
|
||||
await interaction.followUp({ |
await interaction |
||||
|
.followUp({ |
||||
content: `Page 1 of ${embeds.length}:`, |
content: `Page 1 of ${embeds.length}:`, |
||||
embeds: [embeds[index]], |
embeds: [embeds[index]], |
||||
components: [row], |
components: [row], |
||||
fetchReply: true, |
fetchReply: true, |
||||
}) |
}) |
||||
.then(async p => { |
.then(async (p) => { |
||||
const paginatorMessage = p as Message; |
const paginatorMessage = p as Message; |
||||
const filter = i => i.user.id === interaction.user.id; |
const filter = (i) => i.user.id === interaction.user.id; |
||||
|
|
||||
const paginatorCollector = paginatorMessage.createMessageComponentCollector({ |
const paginatorCollector = |
||||
componentType: 'BUTTON', |
paginatorMessage.createMessageComponentCollector({ |
||||
|
componentType: "BUTTON", |
||||
filter: filter, |
filter: filter, |
||||
}); |
}); |
||||
|
|
||||
paginatorCollector.on('collect', async i => { |
paginatorCollector.on("collect", async (i) => { |
||||
switch (i.customId) { |
switch (i.customId) { |
||||
case 'paginator-left': |
case "paginator-left": |
||||
index--; |
index--; |
||||
if (index < 0) index = embeds.length - 1; |
if (index < 0) index = embeds.length - 1; |
||||
break; |
break; |
||||
case 'paginator-right': |
case "paginator-right": |
||||
index++; |
index++; |
||||
if (index > embeds.length - 1) index = 0; |
if (index > embeds.length - 1) index = 0; |
||||
break; |
break; |
||||
} |
} |
||||
await i.update({ content: `Page ${index + 1} of ${embeds.length}:`, embeds: [embeds[index]] }); |
await i.update({ |
||||
|
content: `Page ${index + 1} of ${embeds.length}:`, |
||||
|
embeds: [embeds[index]], |
||||
|
}); |
||||
}); |
}); |
||||
}); |
}); |
||||
} |
} |
Loading…
Reference in new issue