Skip to content

Commit

Permalink
💭 Now can manage messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Maseshi committed May 2, 2024
1 parent dd2003b commit 38f7165
Show file tree
Hide file tree
Showing 8 changed files with 1,453 additions and 75 deletions.
75 changes: 0 additions & 75 deletions source/commands/me/say.js

This file was deleted.

57 changes: 57 additions & 0 deletions source/commands/messages/attachment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js')

module.exports = {
permissions: [
PermissionFlagsBits.SendMessages,
PermissionFlagsBits.AttachFiles,
],
data: new SlashCommandBuilder()
.setName('attachment')
.setDescription('Upload the file and send it in the chat.')
.setDescriptionLocalizations({
th: 'อัปโหลดไฟล์แล้วส่งไปในแชท',
})
.setDefaultMemberPermissions(PermissionFlagsBits.AttachFiles)
.setDMPermission(true)
.addAttachmentOption((option) =>
option
.setName('attachment')
.setDescription('Things to be attached to the message to be sent.')
.setDescriptionLocalizations({
th: 'สิ่งที่ต้องการแนบไปด้วยข้อความที่จะส่ง',
})
.setRequired(true)
)
.addChannelOption((option) =>
option
.setName('channel')
.setDescription('The channel to send the attachment to')
.setDescriptionLocalizations({
th: 'ช่องที่จะส่งไฟล์',
})
.setRequired(false)
),
async execute(interaction) {
const inputAttachment = interaction.options.getAttachment('attachment')
const inputChannel = interaction.options.getChannel('channel') ?? null

if (!inputChannel) {
await interaction.channel.send({
files: [inputAttachment],
})
} else {
await inputChannel.send({
files: [inputAttachment],
})
}

await interaction.reply({
content: inputChannel
? interaction.client.i18n.t('commands.attachment.sended_to_channel')
: interaction.client.i18n.t('commands.attachment.sended', {
id: inputChannel.id,
}),
ephemeral: true,
})
},
}
76 changes: 76 additions & 0 deletions source/commands/messages/crosspost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const {
SlashCommandBuilder,
ChannelType,
PermissionFlagsBits,
} = require('discord.js')
const { catchError } = require('../../utils/consoleUtils')

module.exports = {
permissions: [
PermissionFlagsBits.SendMessages,
PermissionFlagsBits.ManageMessages,
],
data: new SlashCommandBuilder()
.setName('crosspost')
.setDescription(
'Publishes a message in an announcement channel to all channels following it.'
)
.setDescriptionLocalizations({
th: 'เผยแพร่ข้อความในช่องประกาศไปยังทุกช่องที่ติดตาม',
})
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages)
.setDMPermission(true)
.addStringOption((option) =>
option
.setName('id')
.setDescription('ID of message to be published')
.setDescriptionLocalizations({
th: 'ไอดีของข้อความที่ต้องการเผยแพร่',
})
.setRequired(true)
),
async execute(interaction) {
const inputID = interaction.options.getString('id')

if (interaction.channel.type !== ChannelType.GuildAnnouncement)
return await interaction.reply({
content: interaction.client.i18n.t(
'commands.crosspost.is_not_valid_type'
),
ephemeral: true,
})

try {
const message = await interaction.channel.messages.fetch(inputID)

if (!message)
return await interaction.reply({
content: interaction.client.i18n.t(
'commands.crosspost.message_not_found'
),
ephemeral: true,
})
if (!message.crosspostable)
return await interaction.reply({
content: interaction.client.i18n.t(
'commands.crosspost.can_not_published'
),
ephemeral: true,
})

await message.crosspost()
} catch (error) {
catchError(
interaction.client,
interaction,
module.exports.data.name,
error
)
}

await interaction.reply({
content: interaction.client.i18n.t('commands.crosspost.published'),
ephemeral: true,
})
},
}
60 changes: 60 additions & 0 deletions source/commands/messages/delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js')
const { catchError } = require('../../utils/consoleUtils')

module.exports = {
permissions: [
PermissionFlagsBits.SendMessages,
PermissionFlagsBits.ManageMessages,
],
data: new SlashCommandBuilder()
.setName('delete')
.setDescription('Delete unwanted messages')
.setDescriptionLocalizations({
th: 'ลบข้อความที่ไม่ต้องการ',
})
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages)
.setDMPermission(true)
.addStringOption((option) =>
option
.setName('id')
.setDescription('ID of the message you want to delete')
.setDescriptionLocalizations({
th: 'ไอดีของข้อความที่ต้องการลบ',
})
.setRequired(true)
),
async execute(interaction) {
const inputID = interaction.options.getString('id')

try {
const message = await interaction.channel.messages.fetch(inputID)

if (!message)
return await interaction.reply({
content: interaction.client.i18n.t(
'commands.delete.message_not_found'
),
ephemeral: true,
})
if (!message.deleteable)
return await interaction.reply({
content: interaction.client.i18n.t('commands.delete.can_not_delete'),
ephemeral: true,
})

await message.delete()
} catch (error) {
catchError(
interaction.client,
interaction,
module.exports.data.name,
error
)
}

await interaction.reply({
content: interaction.client.i18n.t('commands.delete.deleted'),
ephemeral: true,
})
},
}
Loading

0 comments on commit 38f7165

Please sign in to comment.