Skip to content

Commit ae99698

Browse files
Merge pull request #111 from InsertSoda/main
Slash commands
2 parents 896c04a + d1c1e69 commit ae99698

31 files changed

Lines changed: 499 additions & 233 deletions

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
TOKEN=
2+
CLIENTID=

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
{
22
"name": "polytoria-community-bot",
3-
"version": "2.7.1",
3+
"version": "3.0.0",
44
"type": "module",
55
"typings": "./types",
66
"scripts": {
77
"start": "node dist/index.js",
88
"build": "tsc",
99
"format": "prettier --write .",
10-
"lint": "npx eslint \"src/**\" --fix"
10+
"lint": "npx eslint \"src/**\" --fix",
11+
"deploy": "node dist/deploy-commands.js",
12+
"dev": "npm run build && npm run start"
1113
},
1214
"license": "MIT",
1315
"dependencies": {

src/commands/commands.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { EmbedBuilder, Message } from 'discord.js'
1+
import { CommandInteraction, EmbedBuilder } from 'discord.js'
22

3-
export async function commands (message: Message) {
3+
export async function commands (interaction:CommandInteraction) {
44
const embed: EmbedBuilder = new EmbedBuilder()
55
.setColor(0xFF5454)
66
.setTitle('This command is currently unavailable.')
@@ -11,5 +11,5 @@ export async function commands (message: Message) {
1111
)
1212
.setFooter({ text: 'Thank you for your patience.', iconURL: 'https://starmanthegamer.com/icon.png' })
1313

14-
await message.channel.send({ embeds: [embed] })
14+
await interaction.reply({ embeds: [embed] })
1515
}

src/commands/cookie.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Message } from 'discord.js'
1+
import { CommandInteraction } from 'discord.js'
22

3-
export async function cookie (message: Message, args: any[]): Promise<Message<boolean>> {
4-
return await message.reply('🍪')
3+
export async function cookie (interaction:CommandInteraction) {
4+
await interaction.reply('🍪')
55
}

src/commands/guild/guilds.ts

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Message, EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder, ButtonBuilder, ButtonStyle, ComponentType, BaseInteraction } from 'discord.js'
1+
import { EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder, ButtonBuilder, ButtonStyle, ComponentType, BaseInteraction, CommandInteraction } from 'discord.js'
22
import axios from 'axios'
33
import { responseHandler } from '../../utils/responseHandler.js'
44
import { dateUtils } from '../../utils/dateUtils.js'
@@ -7,21 +7,28 @@ import { fetchMembers } from './GuildMembers.js'
77
import { fetchStore } from './GuildStore.js'
88
import { fetchShouts } from './GuildShouts.js'
99

10-
export async function guild (message: Message, args: string[]): Promise<Message | null> {
11-
const guildID: number = parseInt(args[0])
10+
export async function guild (interaction:CommandInteraction) {
11+
// @ts-expect-error
12+
const guildID = interaction.options.getInteger('id')
1213

13-
if (args.length === 0) {
14-
return message.reply('Please provide me with a guild ID before I can continue!')
14+
if (guildID.length === 0) {
15+
return await interaction.reply('Please provide me with a guild ID before I can continue!')
1516
}
1617

18+
await interaction.deferReply()
19+
1720
const response = await axios.get(`https://api.polytoria.com/v1/guilds/${guildID}`, { validateStatus: () => true })
1821
const data = response.data
1922
const creator = data.creator
2023

2124
const errResult = responseHandler.checkError(response)
2225

2326
if (errResult.hasError === true) {
24-
return message.channel.send(errResult.displayText)
27+
if (errResult.statusCode === 404) {
28+
return await interaction.editReply("Couldn't find the requested guild. Did you type in the correct guild ID?")
29+
} else {
30+
return await interaction.editReply(errResult.displayText)
31+
}
2532
}
2633

2734
let joinType!: string
@@ -129,7 +136,7 @@ export async function guild (message: Message, args: string[]): Promise<Message
129136
const actionRow = new ActionRowBuilder<StringSelectMenuBuilder>()
130137
.addComponents(dropdown)
131138

132-
const reply = await message.reply({
139+
const reply = await interaction.editReply({
133140
embeds: [embed],
134141
components: [actionRow]
135142
})
@@ -142,17 +149,17 @@ export async function guild (message: Message, args: string[]): Promise<Message
142149

143150
const collector = reply.createMessageComponentCollector({
144151
componentType: ComponentType.SelectMenu,
145-
filter: (interaction: BaseInteraction) => (
146-
interaction.isStringSelectMenu() && interaction.customId === 'dropdown_menu' &&
147-
interaction.user.id === message.author.id
152+
filter: (messageInteraction: BaseInteraction) => (
153+
messageInteraction.isStringSelectMenu() && messageInteraction.customId === 'dropdown_menu' &&
154+
messageInteraction.user.id === interaction.user.id
148155
),
149156
time: 60000
150157
})
151158

152-
collector.on('collect', async (interaction) => {
153-
await interaction.deferUpdate()
159+
collector.on('collect', async (messageInteraction) => {
160+
await messageInteraction.deferUpdate()
154161

155-
selectedOption = interaction.values[0]
162+
selectedOption = messageInteraction.values[0]
156163

157164
if (selectedOption === 'guild_option') {
158165
await interaction.editReply({
@@ -200,14 +207,14 @@ export async function guild (message: Message, args: string[]): Promise<Message
200207
filter: (btnInteraction: BaseInteraction) => (
201208
btnInteraction.isButton() &&
202209
btnInteraction.customId === 'prev_button' &&
203-
btnInteraction.user.id === message.author.id
210+
btnInteraction.user.id === interaction.user.id
204211
),
205212
time: 60000
206213
})
207214

208-
prevButtonCollector.on('collect', async (interaction) => {
215+
prevButtonCollector.on('collect', async (buttonInteraction) => {
209216
try {
210-
await interaction.deferUpdate()
217+
await buttonInteraction.deferUpdate()
211218

212219
if (selectedOption === 'members_option' && memberPage > 1) {
213220
memberPage--
@@ -258,14 +265,14 @@ export async function guild (message: Message, args: string[]): Promise<Message
258265
filter: (btnInteraction: BaseInteraction) => (
259266
btnInteraction.isButton() &&
260267
btnInteraction.customId === 'next_button' &&
261-
btnInteraction.user.id === message.author.id
268+
btnInteraction.user.id === interaction.user.id
262269
),
263270
time: 60000
264271
})
265272

266-
nextButtonCollector.on('collect', async (interaction) => {
273+
nextButtonCollector.on('collect', async (buttonInteraction) => {
267274
try {
268-
await interaction.deferUpdate()
275+
await buttonInteraction.deferUpdate()
269276

270277
if (selectedOption === 'members_option') {
271278
memberPage++
@@ -310,6 +317,4 @@ export async function guild (message: Message, args: string[]): Promise<Message
310317
console.error('Error handling interaction:', error)
311318
}
312319
})
313-
314-
return reply
315320
}

src/commands/info.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { EmbedBuilder, Message, ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js'
1+
import { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction } from 'discord.js'
22

3-
export async function info (message: Message) {
3+
export async function info (interaction:CommandInteraction) {
44
const invite = new ButtonBuilder()
5-
.setLabel('Invite us!')
5+
.setLabel('Invite the bot to your server!')
66
.setURL('https://discord.com/api/oauth2/authorize?client_id=905979909049028649&permissions=414464724032&scope=bot')
77
.setStyle(ButtonStyle.Link)
88

99
const github = new ButtonBuilder()
10-
.setLabel('GitHub')
10+
.setLabel('GitHub Repository')
1111
.setURL('https://github.com/Polytoria/CommunityBot')
1212
.setStyle(ButtonStyle.Link)
1313

@@ -21,9 +21,9 @@ export async function info (message: Message) {
2121
.setThumbnail('https://starmanthegamer.com/icon.png')
2222
.addFields(
2323
{ name: 'Version', value: `Currently running version: ${process.env.npm_package_version}` },
24-
{ name: 'Contributed by:', value: 'baggy, Hu Tao, Shiggy, and many more!', inline: true }
24+
{ name: 'Contributed by:', value: 'baggy, DevPixels, Index, InsertSoda, and many more!', inline: true }
2525
)
2626
.setFooter({ text: 'Thank you for using Polytoria Community Bot!', iconURL: 'https://starmanthegamer.com/icon.png' })
2727

28-
await message.channel.send({ embeds: [embed], components: [row] })
28+
await interaction.reply({ embeds: [embed], components: [row] })
2929
}

src/commands/place.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
import { Message, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js'
1+
import { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction } from 'discord.js'
22
import axios from 'axios'
33
import { responseHandler } from '../utils/responseHandler.js'
44
import { dateUtils } from '../utils/dateUtils.js'
55
import emojiUtils from '../utils/emojiUtils.js'
66

7-
export async function place (message: Message, args: string[]) {
8-
const placeID = parseInt(args[0])
7+
export async function place (interaction:CommandInteraction) {
8+
// @ts-expect-error
9+
const placeID = interaction.options.getInteger('id')
910

10-
if (args.length === 0) {
11-
return message.reply('Please provide me with a place ID before I can continue!')
11+
if (placeID.length === 0) {
12+
return await interaction.reply('Please provide me with a place ID before I can continue!')
1213
}
1314

15+
await interaction.deferReply()
16+
1417
const response = await axios.get(`https://api.polytoria.com/v1/places/${placeID}`, { validateStatus: () => true })
1518
const data = response.data
1619
const rating = data.rating
@@ -19,7 +22,11 @@ export async function place (message: Message, args: string[]) {
1922
const errResult = responseHandler.checkError(response)
2023

2124
if (errResult.hasError === true) {
22-
return message.channel.send(errResult.displayText)
25+
if (errResult.statusCode === 404) {
26+
return await interaction.editReply("Couldn't find the requested place. Did you type in the correct place ID?")
27+
} else {
28+
return await interaction.editReply(errResult.displayText)
29+
}
2330
}
2431

2532
let externalDesc = ''
@@ -119,7 +126,7 @@ export async function place (message: Message, args: string[]) {
119126
.setStyle(ButtonStyle.Link)
120127
)
121128

122-
return message.reply({
129+
return await interaction.editReply({
123130
embeds: [embed],
124131
components: [actionRow]
125132
})

src/commands/random.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { Message, EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder, ComponentType, BaseInteraction, StringSelectMenuOptionBuilder } from 'discord.js'
1+
import { EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder, ComponentType, BaseInteraction, StringSelectMenuOptionBuilder, CommandInteraction } from 'discord.js'
22

33
// Import Random Files
44
import { randomPlace } from './random/randomPlace.js'
55
import { randomUser } from './random/randomUser.js'
66
import { randomGuild } from './random/randomGuild.js'
77
import { randomStore } from './random/randomStore.js'
88

9-
export async function random (message: Message, args: any[]) {
9+
export async function random (interaction:CommandInteraction) {
1010
let InitialType: any = null
1111

1212
const embed = new EmbedBuilder()
@@ -49,56 +49,56 @@ export async function random (message: Message, args: any[]) {
4949
selectMenu
5050
)
5151

52-
const reply = await message.reply({
52+
const reply = await interaction.reply({
5353
embeds: [embed],
5454
components: [actionRow]
5555
})
5656

5757
const selectCollector = reply.createMessageComponentCollector({
5858
componentType: ComponentType.StringSelect,
59-
filter: (interaction: BaseInteraction) => (
60-
interaction.isStringSelectMenu() && interaction.user.id === message.author.id
59+
filter: (selectInteraction: BaseInteraction) => (
60+
selectInteraction.isStringSelectMenu() && selectInteraction.user.id === interaction.user.id
6161
),
6262
time: 60000
6363
})
6464

65-
selectCollector.on('collect', async (interaction) => {
66-
if (interaction.customId === 'select') {
67-
InitialType = interaction.values[0] // Update InitialType here
68-
await interaction.deferUpdate()
65+
selectCollector.on('collect', async (selectInteraction) => {
66+
if (selectInteraction.customId === 'select') {
67+
InitialType = selectInteraction.values[0] // Update InitialType here
68+
await selectInteraction.deferUpdate()
6969
update(InitialType, reply)
7070
}
7171
})
7272

7373
const buttonCollector = reply.createMessageComponentCollector({
7474
componentType: ComponentType.Button,
75-
filter: (interaction: BaseInteraction) => (
76-
interaction.isButton() && interaction.user.id === message.author.id && interaction.customId === 'redo_button'
75+
filter: (buttonInteraction: BaseInteraction) => (
76+
buttonInteraction.isButton() && buttonInteraction.user.id === interaction.user.id && buttonInteraction.customId === 'redo_button'
7777
),
7878
time: 60000
7979
})
8080

81-
buttonCollector.on('collect', async (interaction) => {
81+
buttonCollector.on('collect', async (buttonInteraction) => {
8282
if (InitialType !== null) {
8383
update(InitialType, reply)
84-
await interaction.deferUpdate()
84+
await buttonInteraction.deferUpdate()
8585
}
8686
})
8787

8888
async function update (id: string, reply: any) {
8989
let Response: any = null
9090
switch (id) {
9191
case 'place':
92-
Response = await randomPlace(message, args)
92+
Response = await randomPlace(interaction)
9393
break
9494
case 'user':
95-
Response = await randomUser(message, args)
95+
Response = await randomUser(interaction)
9696
break
9797
case 'guild':
98-
Response = await randomGuild(message, args)
98+
Response = await randomGuild(interaction)
9999
break
100100
case 'store':
101-
Response = await randomStore(message, args)
101+
Response = await randomStore(interaction)
102102
break
103103
}
104104

src/commands/random/randomGuild.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Message, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js'
1+
import { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction } from 'discord.js'
22
import emojiUtils from '../../utils/emojiUtils.js'
33
import { dateUtils } from '../../utils/dateUtils.js'
44
import { randomUtils } from '../../utils/randomUtils.js'
55

6-
export async function randomGuild (message: Message, args: string[]) {
6+
export async function randomGuild (interaction: CommandInteraction): Promise<any> {
77
const randomId = randomUtils.randomInt(1, 545)
88
const apiUrl = `https://api.polytoria.com/v1/guilds/${randomId}`
99

@@ -19,7 +19,7 @@ export async function randomGuild (message: Message, args: string[]) {
1919
)
2020

2121
if (randomData == null) {
22-
return message.channel.send('Guild not found, Please try again..')
22+
return await randomGuild(interaction)
2323
}
2424

2525
const data = randomData.data

src/commands/random/randomPlace.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Message, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js'
1+
import { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction } from 'discord.js'
22
import { dateUtils } from '../../utils/dateUtils.js'
33
import { randomUtils } from '../../utils/randomUtils.js'
44
import emojiUtils from '../../utils/emojiUtils.js'
55

6-
export async function randomPlace (message: Message, args: string[]) {
7-
const randomId = randomUtils.randomInt(1, 7667)
6+
export async function randomPlace (interaction: CommandInteraction): Promise<any> {
7+
const randomId = randomUtils.randomInt(1, 7940)
88
const apiUrl = `https://api.polytoria.com/v1/places/${randomId}`
99

1010
const randomData = await randomUtils.randomize(
@@ -19,7 +19,7 @@ export async function randomPlace (message: Message, args: string[]) {
1919
)
2020

2121
if (!randomData || !randomData.data) {
22-
return message.channel.send('Place not found, please try again.')
22+
return await randomPlace(interaction)
2323
}
2424

2525
const data = randomData.data

0 commit comments

Comments
 (0)