Skip to content

Commit

Permalink
Remove unused codes, update discordx and deprecated dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
AshakaE committed Jul 31, 2024
1 parent 2e24fbf commit fce8bc7
Show file tree
Hide file tree
Showing 15 changed files with 1,842 additions and 5,252 deletions.
6,730 changes: 1,744 additions & 4,986 deletions package-lock.json

Large diffs are not rendered by default.

45 changes: 23 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,35 @@
"serve": "node build/main.js"
},
"dependencies": {
"@discordx/importer": "^1.1.2",
"@discordx/pagination": "^2.0.1",
"@discordx/utilities": "^4.1.0",
"axios": "^1.6.8",
"discord.js": "^13.6.0",
"discordx": "^9.5.3",
"@discordx/di": "^3.3.2",
"@discordx/importer": "^1.3.1",
"@discordx/pagination": "^3.5.4",
"@discordx/utilities": "^7.0.1",
"axios": "^1.7.2",
"discord.js": "^14.15.3",
"discordx": "^11.12.0",
"ethers": "^5.6.9",
"graphql": "^16.8.1",
"graphql-request": "^4.2.0",
"graphql": "^16.9.0",
"graphql-request": "^7.1.0",
"node-cache": "^5.1.2",
"node-fetch": "^3.2.9",
"node-schedule": "^2.1.0",
"reflect-metadata": "^0.1.13",
"tsyringe": "^4.6.0",
"twitter-api-v2": "^1.12.9"
"node-fetch": "^3.3.2",
"node-schedule": "^2.1.1",
"reflect-metadata": "^0.2.2",
"tsyringe": "^4.8.0",
"twitter-api-v2": "^1.17.2"
},
"devDependencies": {
"@discordx/changelog": "^2.0.7",
"@types/node": "^17.0.31",
"@types/node-schedule": "^2.1.0",
"dotenv": "^16.0.1",
"nodemon": "^1.4.1",
"prettier": "^2.6.1",
"ts-node": "^10.7.0",
"typescript": "^4.6.4"
"@types/node": "^22.0.0",
"@types/node-schedule": "^2.1.7",
"dotenv": "^16.4.5",
"nodemon": "^3.1.4",
"prettier": "^3.3.3",
"ts-node": "^10.9.2",
"typescript": "^5.5.4"
},
"engines": {
"node": ">=16.0.0",
"npm": ">=7.0.0"
"node": ">=20.0.0",
"npm": ">=10.0.0"
}
}
26 changes: 0 additions & 26 deletions src/commands/choices.ts

This file was deleted.

14 changes: 7 additions & 7 deletions src/commands/context.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ContextMenuInteraction } from "discord.js";
import { ApplicationCommandType, MessageContextMenuCommandInteraction, UserContextMenuCommandInteraction } from "discord.js";
import { Discord, ContextMenu } from "discordx";

@Discord()
export abstract class contextTest {
@ContextMenu("MESSAGE", "message context")
async messageHandler(interaction: ContextMenuInteraction) {
interaction.reply("I am user context handler");
@ContextMenu({ name: 'MESSAGE', type: ApplicationCommandType.Message })
async messageHandler(interaction: MessageContextMenuCommandInteraction) {
interaction.reply('I am user context handler')
}

@ContextMenu("USER", "user context")
async userHandler(interaction: ContextMenuInteraction) {
interaction.reply("I am user context handler");
@ContextMenu({ name: 'USER', type: ApplicationCommandType.User })
async userHandler(interaction: UserContextMenuCommandInteraction) {
interaction.reply('I am user context handler')
}
}
55 changes: 28 additions & 27 deletions src/commands/menu.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import {
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
CommandInteraction,
MessageActionRow,
SelectMenuInteraction,
MessageSelectMenu,
MessageActionRowComponentBuilder,
StringSelectMenuBuilder,
StringSelectMenuInteraction,

} from "discord.js";
import { Discord, Slash, SelectMenuComponent } from "discordx";

Expand All @@ -14,43 +18,40 @@ const roles = [

@Discord()
export abstract class buttons {
@SelectMenuComponent("role-menu")
async handle(interaction: SelectMenuInteraction): Promise<unknown> {
await interaction.deferReply();
@SelectMenuComponent({ id: 'role-menu' })
async handle(interaction: StringSelectMenuInteraction): Promise<unknown> {
await interaction.deferReply()

// extract selected value by member
const roleValue = interaction.values?.[0];
const roleValue = interaction.values?.[0]

// if value not found
if (!roleValue) {
return await interaction.followUp("invalid role id, select again");
return await interaction.followUp('invalid role id, select again')
}

await interaction.followUp(
`you have selected role: ${
roles.find((r) => r.value === roleValue)?.label
}`
);
return;
roles.find(r => r.value === roleValue)?.label
}`,
)
return
}

@Slash("my_roles", { description: "roles menu" })
async myRoles(interaction: CommandInteraction): Promise<unknown> {
await interaction.deferReply();

// create menu for roles
const menu = new MessageSelectMenu()
.addOptions(roles)
.setCustomId("role-menu");
@Slash({ description: 'roles menu', name: 'my-roles' })
async myRoles(interaction: CommandInteraction): Promise<void> {
const btn = new ButtonBuilder()
.setLabel('Hello')
.setStyle(ButtonStyle.Primary)
.setCustomId('hello')

// create a row for message actions
const buttonRow = new MessageActionRow().addComponents(menu);
const buttonRow =
new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(
btn,
)

// send it
interaction.editReply({
content: "select your role!",
interaction.reply({
components: [buttonRow],
});
return;
})
}
}
46 changes: 0 additions & 46 deletions src/commands/simple command.ts

This file was deleted.

39 changes: 0 additions & 39 deletions src/commands/slash + button.ts

This file was deleted.

37 changes: 0 additions & 37 deletions src/commands/slash group.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/commands/slashes.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/events/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class AppDiscord {
this.DEV_URL = process.env.DEV_URL
}

@On('ready')
@On({event: 'ready'})
async isReady([client]: ArgsOf<'ready'>) {
const channelIds = JSON.parse(process.env.CHANNELS)

Expand Down
23 changes: 10 additions & 13 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Client, DIService } from "discordx";
import { Client, DIService, tsyringeDependencyRegistryEngine } from "discordx";
import "reflect-metadata";
import { Intents, Interaction, Message } from "discord.js";
import { container } from 'tsyringe'
import { IntentsBitField, Interaction, Message } from "discord.js";
import { dirname, importx } from "@discordx/importer";
import 'dotenv/config'
import { container } from 'tsyringe'

export const client = new Client({
simpleCommand: {
prefix: "!",
},
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_VOICE_STATES,
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.GuildMessageReactions,
IntentsBitField.Flags.GuildVoiceStates,
],
// If you only want to use global commands only, comment this line
botGuilds: [(client) => client.guilds.cache.map((guild) => guild.id)],
Expand All @@ -26,10 +26,7 @@ client.once("ready", async () => {
await client.guilds.fetch();

// init all application commands
await client.initApplicationCommands({
guild: { log: true },
global: { log: true },
});
await client.initApplicationCommands();

// init permissions; enabled log to see changes
// await client.initApplicationPermissions(true);
Expand All @@ -53,7 +50,7 @@ client.on("messageCreate", (message: Message) => {

async function run() {

DIService.container = container
DIService.engine = tsyringeDependencyRegistryEngine.setInjector(container)
// with cjs
// await importx(dirname + "/{events,commands}/**/*.{ts,js}");
// with ems
Expand Down
Loading

0 comments on commit fce8bc7

Please sign in to comment.