diff --git a/source/commands/developer/logs.js b/source/commands/developer/logs.js index 2d18234f..493adaf3 100644 --- a/source/commands/developer/logs.js +++ b/source/commands/developer/logs.js @@ -9,7 +9,7 @@ module.exports = { "permissions": { "client": [PermissionsBitField.Flags.SendMessages] }, - "usage": "logs , delete> (type: catch, debug, error, process) (file)", + "usage": "logs: get [type], read [file(String)], delete [file(String)]", "function": { "command": {} } @@ -20,7 +20,6 @@ module.exports.function.command = { "name": module.exports.name, "description": module.exports.description, "description_localizations": { - "en-US": "Manage logs files saved in the system.", "th": "จัดการล็อกไฟล์ที่บันทึกไว้ในระบบ" }, "options": [ @@ -120,59 +119,65 @@ module.exports.function.command = { ] }, async execute(interaction) { + const subCommand = interaction.options.getSubcommand(); + const folderPath = "./source/logs/"; - if (interaction.options.getSubcommand() === "get") { - const inputType = interaction.options.getString("type"); + switch (subCommand) { + case "get": + const inputGetType = interaction.options.getString("type"); - try { - const logs = readdirSync(folderPath).filter(files => files.endsWith(".log")); - const listFilename = logs.filter(log => log.includes(inputType)); + try { + const logs = readdirSync(folderPath).filter(files => files.endsWith(".log")); + const listFilename = logs.filter(log => log.includes(inputGetType)); - if (listFilename) { - return await interaction.editReply(interaction.client.translate.commands.logs.found_file.replace("%s1", listFilename.length).replace("%s2", listFilename.join(" \n"))); - } else { - return await interaction.editReply(interaction.client.translate.commands.logs.file_not_found.replace("%s", inputType)); + if (listFilename) { + await interaction.reply(interaction.client.translate.commands.logs.found_file.replace("%s1", listFilename.length).replace("%s2", listFilename.join(" \n"))); + } else { + await interaction.reply(interaction.client.translate.commands.logs.file_not_found.replace("%s", inputGetType)); + } + } catch (error) { + await interaction.reply(interaction.client.translate.commands.logs.folder_empty); } - } catch (error) { - return await interaction.editReply(interaction.client.translate.commands.logs.folder_empty); - } - } - if (interaction.options.getSubcommand() === "read") { - const inputFilename = interaction.options.getString("filename"); - - try { - const fileString = readFileSync(folderPath + inputFilename, "utf8"); + break; + case "read": + const inputReadFilename = interaction.options.getString("filename"); - return await interaction.editReply("```JavaScript\n%s\n```".replace("%s", fileString)); - } catch { try { - const fileString = readFileSync(folderPath + inputFilename + ".log", "utf8"); + const fileString = readFileSync(folderPath + inputReadFilename, "utf8"); - return await interaction.editReply("```JavaScript\n%s\n```".replace("%s", fileString)); - } catch (error) { - return await interaction.editReply(interaction.client.translate.commands.logs.can_not_read_file.replace("%s", error)); - } - } - } - if (interaction.options.getSubcommand() === "delete") { - const inputFilename = interaction.options.getString("filename"); + await interaction.reply("```JavaScript\n%s\n```".replace("%s", fileString)); + } catch { + try { + const fileString = readFileSync(folderPath + inputReadFilename + ".log", "utf8"); - if (interaction.user.id !== interaction.client.config.owner) return interaction.editReply(interaction.client.translate.commands.logs.owner_only); + await interaction.reply("```JavaScript\n%s\n```".replace("%s", fileString)); + } catch (error) { + await interaction.reply(interaction.client.translate.commands.logs.can_not_read_file.replace("%s", error)); + } + } + break; + case "delete": + const inputDeleteFilename = interaction.options.getString("filename"); - try { - unlinkSync(folderPath + inputFilename); + if ((interaction.user.id !== interaction.client.config.team.owner) || (!interaction.client.config.team.developer.includes(interaction.user.id))) { + return interaction.reply(interaction.client.translate.commands.logs.owner_only); + } - return await interaction.editReply(interaction.client.translate.commands.logs.file_has_been_deleted.replace("%s", inputFilename)); - } catch { try { - unlinkSync(folderPath + inputFilename + ".log"); + unlinkSync(folderPath + inputDeleteFilename); - return await interaction.editReply(interaction.client.translate.commands.logs.file_has_been_deleted.replace("%s", inputFilename)); - } catch (error) { - return await interaction.editReply(interaction.client.translate.commands.logs.can_not_delete_file.replace("%s", error)); + await interaction.reply(interaction.client.translate.commands.logs.file_has_been_deleted.replace("%s", inputDeleteFilename)); + } catch { + try { + unlinkSync(folderPath + inputDeleteFilename + ".log"); + + await interaction.reply(interaction.client.translate.commands.logs.file_has_been_deleted.replace("%s", inputDeleteFilename)); + } catch (error) { + await interaction.reply(interaction.client.translate.commands.logs.can_not_delete_file.replace("%s", error)); + } } - } + break; } } } \ No newline at end of file diff --git a/source/commands/developer/ping.js b/source/commands/developer/ping.js index 15261e37..10cf37e7 100644 --- a/source/commands/developer/ping.js +++ b/source/commands/developer/ping.js @@ -18,22 +18,21 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "ping", "th": "ปิง" }, "description": module.exports.description, "description_localizations": { - "en-US": "Check the ping and api latency of the bot.", "th": "ตรวจสอบความหน่วงและ API Latency ของเซิร์ฟเวอร์" } }, async execute(interaction) { - const msg = await interaction.editReply(interaction.client.translate.commands.ping.waiting); - const ping = Math.round((msg.createdTimestamp - interaction.createdTimestamp) - interaction.client.ws.ping); - const api = Math.round(interaction.client.ws.ping); + const message = await interaction.reply({ "content": interaction.client.translate.commands.ping.waiting, "fetchReply": true }); + const roundtrip = message.createdTimestamp - interaction.createdTimestamp; + const websocket = interaction.client.ws.ping; + const pingEmbed = new EmbedBuilder() .setTitle(interaction.client.translate.commands.ping.connection) - .setDescription(interaction.client.translate.commands.ping.info.replace("%s1", ping).replace("%s2", api)) + .setDescription(interaction.client.translate.commands.ping.info.replace("%s1", roundtrip).replace("%s2", websocket)); await interaction.editReply({ "content": interaction.client.translate.commands.ping.result, diff --git a/source/commands/developer/reload.js b/source/commands/developer/reload.js index c6e1ef48..40ecdc8e 100644 --- a/source/commands/developer/reload.js +++ b/source/commands/developer/reload.js @@ -10,7 +10,7 @@ module.exports = { "permissions": { "client": [PermissionsBitField.Flags.SendMessages] }, - "usage": "reload ", + "usage": "reload ", "function": { "command": {} } @@ -20,12 +20,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "reload", "th": "โหลดซ้ำ" }, "description": module.exports.description, "description_localizations": { - "en-US": "Reload the command that doesn't work.", "th": "โหลดคำสั่งที่ไม่ทำงานอีกครั้ง" }, "options": [ @@ -44,32 +42,26 @@ module.exports.function.command = { ] }, async execute(interaction) { - const inputCommand = interaction.options.get("command").value; + const inputCommand = interaction.options.getString("command", true).toLowerCase(); - const commandName = inputCommand.toLowerCase(); - const command = interaction.client.interaction.get(commandName); + const command = interaction.client.commands.get(inputCommand); + const commandName = command.name.toLowerCase(); - if (!command) return await interaction.editReply(interaction.client.translate.commands.reload.invalid_command); + if (!command) return await interaction.reply(interaction.client.translate.commands.reload.invalid_command); - readdirSync(path.join(__dirname, "..")).forEach(async (dirs) => { - const files = readdirSync(path.join(__dirname, "..", dirs)); + delete require.cache[require.resolve("./" + commandName + ".js")]; - if (files.includes(commandName + ".js")) { - const file = "../" + dirs + "/" + commandName + ".js"; + try { + interaction.client.commands.delete(commandName); - try { - delete require.cache[require.resolve(file)]; - interaction.client.interaction.delete(commandName); + const newCommand = require("./" + commandName + ".js"); + const newCommandName = newCommand.name.toLowerCase(); - const pull = require(file); - - interaction.client.interaction.set(commandName, pull); - await interaction.editReply(interaction.client.translate.commands.reload.reloaded.replace("%s", commandName)); - } catch (error) { - await interaction.editReply(interaction.client.translate.commands.reload.reload_error.replace("%s", inputCommand.toUpperCase())); - console.log(error.stack || error); - } - } - }); + interaction.client.commands.set(newCommandName, newCommand); + await interaction.reply(interaction.client.translate.commands.reload.reloaded.replace("%s", inputCommand)); + } catch (error) { + console.error(error); + await interaction.reply(interaction.client.translate.commands.reload.reload_error.replace("%s", inputCommand.toUpperCase())); + } } } diff --git a/source/commands/developer/system.js b/source/commands/developer/system.js index bd1187de..95f3febe 100644 --- a/source/commands/developer/system.js +++ b/source/commands/developer/system.js @@ -20,19 +20,17 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "system", "th": "ระบบ" }, "description": module.exports.description, "description_localizations": { - "en-US": "Get system operating status and more", "th": "รับสถานะการทำงานของระบบและอื่น ๆ" } }, async execute(interaction) { - await interaction.editReply(interaction.client.translate.commands.system.loading); + await interaction.reply(interaction.client.translate.commands.system.loading); - get({ + const data = await get({ "time": "uptime", "system": "manufacturer, model", "bios": "vendor, version, releaseDate", @@ -42,73 +40,101 @@ module.exports.function.command = { "battery": "hasBattery, isCharging, percent, type", "graphics": "controllers, displays", "osInfo": "platform, arch" - }).then(async (data) => { - const serverSeconds = (data.time.uptime / 1000); - const serverDays = Math.floor(serverSeconds / (3600 * 24)); - const serverHours = Math.floor(serverSeconds % (3600 * 24) / 3600); - - const systemManufacturer = data.system.manufacturer; - const systemModel = data.system.model; - - const biosVendor = data.bios.vendor; - const biosVersion = data.bios.version; - const biosReleaseDate = data.bios.releaseDate; - - const cpuManufacturer = data.cpu.manufacturer; - const cpuBrand = data.cpu.brand; - const cpuSpeed = data.cpu.speed; - const cpuCores = data.cpu.cores; - const cpuPhysicalCores = data.cpu.physicalCores; - - const cpuTempMain = data.cpuTemperature.cpuTempMain; - - const memUsed = (data.mem.used / 1024 / 1024).toFixed(2); - const memTotal = (data.mem.total / 1024 / 1024).toFixed(2); - - const batteryHasBattery = data.battery.hasBattery; - const batteryIsCharging = data.battery.isCharging; - const batteryPercent = data.battery.percent; - const batteryType = data.battery.type; - - const gpuControllers = data.graphics.controllers; - const gpuControllersLength = gpuControllers.length; - let gpuMain = "", - gpuMainModel = "", - gpuMainFanSpeed = "", - gpuMainMemoryTotal = "", - gpuMainMemoryUsed = "", - gpuMainTemperatureGpu = ""; - for (let i = 0; i < gpuControllersLength; i++) { - gpuMainModel = gpuControllers[i].model; - gpuMainFanSpeed = gpuControllers[i].fanSpeed; - gpuMainMemoryTotal = gpuControllers[i].memoryTotal; - gpuMainMemoryUsed = gpuControllers[i].memoryUsed; - gpuMainTemperatureGpu = gpuControllers[i].temperatureGpu; - - gpuMain += ("```" + gpuMainModel + ", " + (gpuMainMemoryUsed ? (gpuMainMemoryTotal ? (gpuMainMemoryUsed + "/" + gpuMainMemoryTotal + "MB") : "") : "") + (gpuMainFanSpeed ? gpuMainFanSpeed + " " : "") + (gpuMainTemperatureGpu ? gpuMainTemperatureGpu : "") + "```"); - } - - const gpuDisplays = data.graphics.displays; - const gpuDisplaysLength = gpuDisplays.length; - let gpuSecond = "", - gpuSecondModel = "", - gpuSecondMain = ""; - for (let i = 0; i < gpuDisplaysLength; i++) { - gpuSecondModel = gpuDisplays[i].model; - gpuSecondMain = gpuDisplays[i].main; + }); - gpuSecond += ("```" + gpuSecondModel + ", " + (gpuSecondMain ? interaction.client.translate.commands.system.main : "") + "```"); + // Uptime + const serverSeconds = (data.time.uptime / 1000); + const serverDays = Math.floor(serverSeconds / (3600 * 24)); + const serverHours = Math.floor(serverSeconds % (3600 * 24) / 3600); + + // System + const systemManufacturer = data.system.manufacturer; + const systemModel = data.system.model; + + // BIOS + const biosVendor = data.bios.vendor; + const biosVersion = data.bios.version; + const biosReleaseDate = data.bios.releaseDate; + + // CPU + const cpuManufacturer = data.cpu.manufacturer; + const cpuBrand = data.cpu.brand; + const cpuSpeed = data.cpu.speed; + const cpuCores = data.cpu.cores; + const cpuPhysicalCores = data.cpu.physicalCores; + + // Temperature + const cpuTempMain = data.cpuTemperature.cpuTempMain; + + // Memory + const memUsed = (data.mem.used / 1024 / 1024).toFixed(2); + const memTotal = (data.mem.total / 1024 / 1024).toFixed(2); + + // Battery + const batteryHasBattery = data.battery.hasBattery; + const batteryIsCharging = data.battery.isCharging; + const batteryPercent = data.battery.percent; + const batteryType = data.battery.type; + + // Graphics Controllers + let gpuMain = interaction.client.translate.commands.system.unknown; + const gpuControllers = data.graphics.controllers; + if (gpuControllers.length) { + for (const gpuController of gpuControllers) { + const gpuMainModel = gpuController.model; + const gpuMainFanSpeed = gpuController.fanSpeed; + const gpuMainMemoryTotal = gpuController.memoryTotal; + const gpuMainMemoryUsed = gpuController.memoryUsed; + const gpuMainTemperatureGpu = gpuController.temperatureGpu; + + gpuMain += ( + "```" + + gpuMainModel + + ", " + + ( + gpuMainMemoryUsed ? ( + gpuMainMemoryTotal ? ( + gpuMainMemoryUsed + "/" + gpuMainMemoryTotal + "MB" + ) : "" + ) : "" + ) + + (gpuMainFanSpeed ? (gpuMainFanSpeed + " ") : "") + + (gpuMainTemperatureGpu ?? "") + + "```" + ); } + } - const osPlatform = data.osInfo.platform; - const osArch = data.osInfo.arch; + // Graphics Displays + let gpuSecond = interaction.client.translate.commands.system.unknown; + const gpuDisplays = data.graphics.displays; + for (const gpuDisplay of gpuDisplays) { + const gpuSecondModel = gpuDisplay.model; + const gpuSecondMain = gpuDisplay.main; + + gpuSecond += ( + "```" + + gpuSecondModel + + ", " + + (gpuSecondMain ? interaction.client.translate.commands.system.main : "") + + "```" + ); + } - const clientColor = interaction.guild.members.me.displayHexColor; - const systemEmbed = new EmbedBuilder() - .setTitle(interaction.client.translate.commands.system.info_title) - .setDescription(interaction.client.translate.commands.system.info_description) - .setColor(clientColor) - .addFields([ + // Operating System + const osPlatform = data.osInfo.platform; + const osArch = data.osInfo.arch; + + const clientAvatar = interaction.client.user.displayAvatarURL(); + const clientUsername = interaction.client.user.username; + const clientColor = interaction.guild.members.me.displayHexColor; + const systemEmbed = new EmbedBuilder() + .setColor(clientColor) + .setAuthor({ "iconURL": clientAvatar, "name": clientUsername }) + .setTitle(interaction.client.translate.commands.system.info_title) + .setDescription(interaction.client.translate.commands.system.info_description) + .addFields( + [ { "name": "• Discord.js", "value": "```" + "v" + version + "```", @@ -169,12 +195,12 @@ module.exports.function.command = { "value": "```" + (osPlatform ? (osPlatform + " " + osArch) : interaction.client.translate.commands.system.unknown) + "```", "inline": true } - ]); + ] + ); - await interaction.editReply({ - "content": null, - "embeds": [systemEmbed] - }); + await interaction.editReply({ + "content": null, + "embeds": [systemEmbed] }); } } \ No newline at end of file diff --git a/source/commands/developer/uptime.js b/source/commands/developer/uptime.js index 30caabaf..08cf4c28 100644 --- a/source/commands/developer/uptime.js +++ b/source/commands/developer/uptime.js @@ -18,12 +18,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "uptime", "th": "เวลาทำงาน" }, "description": module.exports.description, "description_localizations": { - "en-US": "Displays the bots current uptime!", "th": "แสดงเวลาทำงานของบอทในปัจจุบัน!" } }, @@ -38,14 +36,15 @@ module.exports.function.command = { min.padStart(2, "0") + " " + interaction.client.translate.commands.uptime.minute + " " + sec.padStart(2, "0") + " " + interaction.client.translate.commands.uptime.second + " "; + const clientAvatar = interaction.client.user.displayAvatarURL(); + const clientUsername = interaction.client.user.username; const clientColor = interaction.guild.members.me.displayHexColor; const uptimeEmbed = new EmbedBuilder() + .setColor(clientColor) + .setAuthor({ "iconURL": clientAvatar, "name": clientUsername }) .setTitle(interaction.client.translate.commands.uptime.info_title) - .setDescription("```" + duration + "```") - .setColor(clientColor); + .setDescription("```" + duration + "```"); - await interaction.editReply({ - "embeds": [uptimeEmbed] - }); + await interaction.reply({ "embeds": [uptimeEmbed] }); } } \ No newline at end of file diff --git a/source/commands/developer/version.js b/source/commands/developer/version.js index 23b97264..d4c25b58 100644 --- a/source/commands/developer/version.js +++ b/source/commands/developer/version.js @@ -19,22 +19,22 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "version", "th": "รุ่น" }, "description": module.exports.description, "description_localizations": { - "en-US": "Check the current bot version.", "th": "ตรวจสอบเวอร์ชันของบอทในปัจจุบัน!" } }, async execute(interaction) { + const clientAvatar = interaction.client.user.displayAvatarURL(); + const clientUsername = interaction.client.user.username; + const clientColor = interaction.guild.members.me.displayHexColor; const versionEmbed = new EmbedBuilder() - .setDescription(interaction.client.translate.commands.version.working_in_version.replace("%s", version)) - .setColor("Green"); + .setColor(clientColor) + .setAuthor({ "iconURL": clientAvatar, "name": clientUsername }) + .setDescription(interaction.client.translate.commands.version.working_in_version.replace("%s", version)); - await interaction.editReply({ - "embeds": [versionEmbed] - }); + await interaction.reply({ "embeds": [versionEmbed] }); } } \ No newline at end of file diff --git a/source/commands/fun/dead.js b/source/commands/fun/dead.js index 8f8305a7..4959ddac 100644 --- a/source/commands/fun/dead.js +++ b/source/commands/fun/dead.js @@ -18,12 +18,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "dead", "th": "เสียชีวิต" }, "description": module.exports.description, "description_localizations": { - "en-US": "Fake message that says you commit suicide.", "th": "ข้อความปลอมที่บอกว่าคุณฆ่าตัวตาย!" } }, @@ -33,8 +31,6 @@ module.exports.function.command = { .setDescription(interaction.client.translate.commands.dead.suicide.replace("%s", authorUsername)) .setColor("Default"); - await interaction.editReply({ - "embeds": [deadEmbed] - }); + await interaction.reply({ "embeds": [deadEmbed] }); } } \ No newline at end of file diff --git a/source/commands/fun/eat.js b/source/commands/fun/eat.js index 4b35e4f4..cee15747 100644 --- a/source/commands/fun/eat.js +++ b/source/commands/fun/eat.js @@ -8,7 +8,7 @@ module.exports = { "permissions": { "client": [PermissionsBitField.Flags.SendMessages] }, - "usage": "eat ", + "usage": "eat ", "function": { "command": {} } @@ -18,12 +18,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "eat", "th": "กิน" }, "description": module.exports.description, "description_localizations": { - "en-US": "Fake text saying who you are eating.", "th": "ข้อความปลอมที่บอกว่าคุณกำลังจะกินใคร!" }, "options": [ @@ -42,7 +40,7 @@ module.exports.function.command = { ] }, async execute(interaction) { - const inputName = interaction.options.get("name").value; + const inputName = interaction.options.getString("name"); const authorUsername = interaction.user.username; const clientUsername = interaction.client.user.username; @@ -51,15 +49,13 @@ module.exports.function.command = { .setColor("Default"); if (inputName === clientUsername) { - return await interaction.editReply("...").then(() => { - setTimeout(async () => { - await interaction.followUp(interaction.client.translate.commands.eat.do_not_eat_me); - }, 8000); - }); + await interaction.reply("..."); + setTimeout(async () => { + await interaction.followUp(interaction.client.translate.commands.eat.do_not_eat_me); + }, 8000); + return; } - await interaction.editReply({ - "embeds": [eatEmbed] - }); + await interaction.reply({ "embeds": [eatEmbed] }); } } \ No newline at end of file diff --git a/source/commands/fun/kill.js b/source/commands/fun/kill.js index ca717ba9..2db8d754 100644 --- a/source/commands/fun/kill.js +++ b/source/commands/fun/kill.js @@ -8,7 +8,7 @@ module.exports = { "permissions": { "client": [PermissionsBitField.Flags.SendMessages] }, - "usage": "kill ", + "usage": "kill ", "function": { "command": {} } @@ -18,12 +18,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "kill", "th": "ฆ่า" }, "description": module.exports.description, "description_localizations": { - "en-US": "Fake messages that say you will kill something.", "th": "ข้อความปลอมที่บอกว่าคุณจะฆ่าอะไรบางอย่าง" }, "options": [ @@ -42,7 +40,7 @@ module.exports.function.command = { ] }, async execute(interaction) { - const inputName = interaction.options.get("name").value; + const inputName = interaction.options.getString("name"); const authorUsername = interaction.user.username; const clientUsername = interaction.client.user.username; @@ -50,10 +48,8 @@ module.exports.function.command = { .setDescription(interaction.client.translate.commands.kill.killed.replace("%s1", authorUsername).replace("%s2", inputName)) .setColor("Default"); - if (inputName === clientUsername) return await interaction.editReply(interaction.client.translate.commands.kill.do_not_kill_me); + if (inputName === clientUsername) return await interaction.reply(interaction.client.translate.commands.kill.do_not_kill_me); - await interaction.editReply({ - "embeds": [killEmbed] - }); + await interaction.reply({ "embeds": [killEmbed] }); } } \ No newline at end of file diff --git a/source/commands/fun/meme.js b/source/commands/fun/meme.js index e0f7e713..08abd590 100644 --- a/source/commands/fun/meme.js +++ b/source/commands/fun/meme.js @@ -1,6 +1,6 @@ const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, PermissionsBitField } = require("discord.js"); const { randomInt } = require("../../utils/miscUtils"); -const fetch = require("node-fetch"); +const { get } = require("axios").default; module.exports = { "enable": true, @@ -10,7 +10,7 @@ module.exports = { "permissions": { "client": [PermissionsBitField.Flags.SendMessages] }, - "usage": "meme [category]", + "usage": "meme [category(String)]", "function": { "command": {} } @@ -20,12 +20,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "meme", "th": "มีม" }, "description": module.exports.description, "description_localizations": { - "en-US": "Randomly select the meme you want.", "th": "สุ่มเลือกมีมที่คุณต้องการ" }, "options": [ @@ -43,36 +41,28 @@ module.exports.function.command = { ] }, async execute(interaction) { - const inputCategory = interaction.options.get("category"); + const inputCategory = interaction.options.getString("category") ?? ""; const randomEmbed = async (choice) => { const category = ["meme", "Memes_Of_The_Dank", "memes", "dankmemes"]; - const random = choice ? choice.value : category[randomInt(category.length)]; + const random = choice ? choice : category[randomInt(category.length)]; - const response = await fetch("https://www.reddit.com/r/" + random + "/random/.json"); - - if (response.status !== 200) { - return new EmbedBuilder() - .setColor("Red") - .setDescription(interaction.client.translate.commands.meme.can_not_fetch); - } - - const data = await response.json(); + try { + const response = await get("https://www.reddit.com/r/" + random + "/random/.json"); - if (!Array.isArray(data) || data.length === 0) { - return new EmbedBuilder() - .setColor("Red") - .setDescription(interaction.client.translate.commands.meme.meme_not_found.replace("%s", choice)); - } + if (!Array.isArray(response.data) || response.data.length === 0) { + return new EmbedBuilder() + .setColor("Red") + .setDescription(interaction.client.translate.commands.meme.meme_not_found.replace("%s", choice)); + } - try { - const permalink = data[0].data.children[0].data.permalink; + const permalink = response.data[0].data.children[0].data.permalink; const memeUrl = "https://reddit.com" + permalink; - const memeImage = data[0].data.children[0].data.url; - const memeTitle = data[0].data.children[0].data.title; - const memeUpvotes = data[0].data.children[0].data.ups; - const memeNumComments = data[0].data.children[0].data.num_comments; - const memeCreate = data[0].data.children[0].data.created; + const memeImage = response.data[0].data.children[0].data.url; + const memeTitle = response.data[0].data.children[0].data.title; + const memeUpvotes = response.data[0].data.children[0].data.ups; + const memeNumComments = response.data[0].data.children[0].data.num_comments; + const memeCreate = response.data[0].data.children[0].data.created; return new EmbedBuilder() .setTitle(memeTitle) @@ -97,13 +87,13 @@ module.exports.function.command = { .setEmoji("🔁") ); - await interaction.editReply({ + await interaction.reply({ "embeds": [memeEmbed], "components": [buttonRow], }); const collector = interaction.channel.createMessageCollector({ - filter: (reactor) => reactor.user.id !== interaction.user.id, + "filter": (reactor) => reactor.member.id !== interaction.member.id, "time": 60, "max": 3, "dispose": true, @@ -124,7 +114,7 @@ module.exports.function.command = { collector.on("end", async () => { buttonRow.components.forEach((button) => button.setDisabled(true)); - return await interaction.editReply({ "components": [buttonRow] }); + await interaction.editReply({ "components": [buttonRow] }); }); } } \ No newline at end of file diff --git a/source/commands/fun/nekos.js b/source/commands/fun/nekos.js index 7bcc7986..5366c9f0 100644 --- a/source/commands/fun/nekos.js +++ b/source/commands/fun/nekos.js @@ -1,5 +1,5 @@ const { EmbedBuilder, PermissionsBitField } = require("discord.js"); -const fetch = require('node-fetch'); +const { get } = require("axios").default; module.exports = { "enable": true, @@ -18,13 +18,8 @@ module.exports = { module.exports.function.command = { "data": { "name": module.exports.name, - "name_localizations": { - "en-US": "nekos", - "th": "เนโกะ" - }, "description": module.exports.description, "description_localizations": { - "en-US": "Random anime pictures as you want.", "th": "สุ่มรูปอนิเมะตามที่คุณต้องการ" }, "options": [ @@ -137,7 +132,7 @@ module.exports.function.command = { ] }, async execute(interaction) { - const inputType = interaction.options.get("type").value; + const inputType = interaction.options.getString("type"); const api = "https://nekos.life/api/v2"; const endpoints = { @@ -166,20 +161,22 @@ module.exports.function.command = { "waifu": "/img/waifu" }; - fetch(api + endpoints[inputType]) - .then(response => response.json()) - .then(async data => { - const title = Object.keys(endpoints).find(key => endpoints[key] === endpoints[inputType]); - const authorUsername = interaction.user.username; - const authorAvatar = interaction.user.displayAvatarURL(); - const nekosEmbed = new EmbedBuilder() - .setTitle(title.charAt(0).toUpperCase() + title.slice(1)) - .setColor("Random") - .setImage(data.url) - .setTimestamp() - .setFooter({ "iconURL": authorAvatar, "text": interaction.client.translate.commands.nekos.request_by.replace("%s", authorUsername) }); + try { + const response = await get(api + endpoints[inputType]); + + const title = Object.keys(endpoints).find(key => endpoints[key] === endpoints[inputType]); + const authorUsername = interaction.user.username; + const authorAvatar = interaction.user.displayAvatarURL(); + const nekosEmbed = new EmbedBuilder() + .setColor("Random") + .setTitle(title.charAt(0).toUpperCase() + title.slice(1)) + .setImage(response.data.url) + .setFooter({ "iconURL": authorAvatar, "text": interaction.client.translate.commands.nekos.request_by.replace("%s", authorUsername) }) + .setTimestamp(); - await interaction.editReply({ "embeds": [nekosEmbed] }); - }); + await interaction.reply({ "embeds": [nekosEmbed] }); + } catch (error) { + await interaction.reply(interaction.client.translate.commands.nekos.can_not_fetch_data); + } } } \ No newline at end of file diff --git a/source/commands/fun/numbers.js b/source/commands/fun/numbers.js index c737fde6..28a39fa6 100644 --- a/source/commands/fun/numbers.js +++ b/source/commands/fun/numbers.js @@ -8,7 +8,7 @@ module.exports = { "permissions": { "client": [PermissionsBitField.Flags.SendMessages] }, - "usage": "numbers ", + "usage": "numbers ", "function": { "command": {} } @@ -18,12 +18,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "numbers", "th": "ตัวเลข" }, "description": module.exports.description, "description_localizations": { - "en-US": "Random number.", "th": "สุ่มตัวเลข" }, "options": [ @@ -54,17 +52,17 @@ module.exports.function.command = { ] }, async execute(interaction) { - let inputMin = interaction.options.get("min").value; - let inputMax = interaction.options.get("max").value; + let inputMin = interaction.options.getNumber("min"); + let inputMax = interaction.options.getNumber("max"); if (inputMin > inputMax) { - const temp = inputMax; + let temp = inputMax; inputMax = inputMin; inputMin = temp; } const result = Math.floor(Math.random() * (inputMax - inputMin + 1)) + inputMin; - await interaction.editReply(interaction.client.translate.commands.numbers.result.replace("%s", result)); + await interaction.reply(interaction.client.translate.commands.numbers.result.replace("%s", result)); } } \ No newline at end of file diff --git a/source/commands/fun/rip.js b/source/commands/fun/rip.js index 4d1f00ea..5fb952d3 100644 --- a/source/commands/fun/rip.js +++ b/source/commands/fun/rip.js @@ -21,21 +21,16 @@ module.exports = { module.exports.function.command = { "data": { "name": module.exports.name, - "name_localizations": { - "en-US": "rip", - "th": "ตาย" - }, "description": module.exports.description, "description_localizations": { - "en-US": "Send RIP images", "th": "ส่งภาพ RIP" } }, async execute(interaction) { const rip = new AttachmentBuilder("https://i.imgur.com/w3duR07.png"); - if (!rip) return await interaction.editReply(interaction.client.translate.commands.rip.no_image); + if (!rip) return await interaction.reply(interaction.client.translate.commands.rip.no_image); - await interaction.editReply({ "files": [rip] }); + await interaction.reply({ "files": [rip] }); } } \ No newline at end of file diff --git a/source/commands/fun/tableFlip.js b/source/commands/fun/tableFlip.js index f13b6f6c..2f17cb3f 100644 --- a/source/commands/fun/tableFlip.js +++ b/source/commands/fun/tableFlip.js @@ -2,13 +2,13 @@ const { PermissionsBitField } = require("discord.js"); module.exports = { "enable": true, - "name": "tableFlip", + "name": "tableflip", "description": "(\\\\°□°)\\\\ ┬─┬", "category": "fun", "permissions": { "client": [PermissionsBitField.Flags.SendMessages] }, - "usage": "tableFlip", + "usage": "tableflip", "function": { "command": {} } @@ -16,9 +16,8 @@ module.exports = { module.exports.function.command = { "data": { - "name": module.exports.name.toLowerCase(), + "name": module.exports.name, "name_localizations": { - "en-US": "tableflip", "th": "พลิกโต๊ะ" }, "description": module.exports.description @@ -32,12 +31,12 @@ module.exports.function.command = { "(╯°□°)╯ ┬─┬" ]; - await interaction.editReply("(\\\\°□°)\\\\ ┬─┬").then(() => { - for (const frame of frames) { - setTimeout(async () => { - await interaction.editReply(frame); - }, 1000); - } - }); + await interaction.reply("(\\\\°□°)\\\\ ┬─┬"); + + for (const frame of frames) { + setTimeout(async () => { + await interaction.editReply(frame); + }, 1000); + } } } \ No newline at end of file diff --git a/source/commands/games/rpc.js b/source/commands/games/rpc.js index 25205368..774ee939 100644 --- a/source/commands/games/rpc.js +++ b/source/commands/games/rpc.js @@ -12,7 +12,7 @@ module.exports = { PermissionsBitField.Flags.ManageMessages ] }, - "usage": "rpc (member)", + "usage": "rpc [opponent]", "function": { "command": {} } @@ -22,12 +22,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "rpc", "th": "เป่ายิ้งฉุบ" }, "description": module.exports.description, "description_localizations": { - "en-US": "Play rock-paper-scissors with friends or me", "th": "เล่นเป่ายิ้งฉุบกับเพื่อนหรือกับฉัน" }, "options": [ @@ -48,7 +46,10 @@ module.exports.function.command = { async execute(interaction) { const inputOpponent = interaction.options.getUser("opponent"); - if (inputOpponent && inputOpponent.bot && (inputOpponent.id !== interaction.client.user.id)) return await interaction.editReply(interaction.client.translate.commands.rpc.can_not_play_with_another_bot); + const member = await interaction.guild.members.fetch(inputOpponent.id); + + if (inputOpponent && !member) return await interaction.reply(interaction.client.translate.commands.rpc.member_not_found); + if (inputOpponent && inputOpponent.bot && (inputOpponent.id !== interaction.client.user.id)) return await interaction.reply(interaction.client.translate.commands.rpc.can_not_play_with_another_bot); const authorUser = interaction.user; const gameObjects = { @@ -78,7 +79,7 @@ module.exports.function.command = { .setStyle(ButtonStyle.Primary) ); - await interaction.editReply({ + await interaction.reply({ "embeds": [rpcEmbed], "components": [rpcRow] }); diff --git a/source/commands/games/snake.js b/source/commands/games/snake.js index 37627516..3d69913f 100644 --- a/source/commands/games/snake.js +++ b/source/commands/games/snake.js @@ -23,12 +23,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "snake", - "th": "สายงู" + "th": "งู" }, "description": module.exports.description, "description_localizations": { - "en-US": "Play a snake board game.", "th": "เล่นเกมกระดานงู" } }, @@ -40,6 +38,8 @@ module.exports.function.command = { let snake = [{ "x": 5, "y": 5 }]; let snakeLength = 1; let score = 0; + let startTime = new Date(); + let endTime = 0; let gameEmbedMessage = null; let inGame = false; @@ -105,6 +105,9 @@ module.exports.function.command = { }; const gameOver = () => { inGame = false; + endTime = new Date(); + + const playTime = endTime - startTime; const authorAvatar = interaction.user.displayAvatarURL(); const authorUsername = interaction.user.username; const editEmbed = new EmbedBuilder() @@ -177,7 +180,7 @@ module.exports.function.command = { snake = [{ "x": 5, "y": 5 }]; newAppleLocation(); - await interaction.editReply(interaction.client.translate.commands.snake.building_board_game); + await interaction.reply(interaction.client.translate.commands.snake.building_board_game); const authorAvatar = interaction.user.displayAvatarURL(); const authorUsername = interaction.user.username; diff --git a/source/commands/games/tictactoe.js b/source/commands/games/tictactoe.js index 3d6921d9..96b499c5 100644 --- a/source/commands/games/tictactoe.js +++ b/source/commands/games/tictactoe.js @@ -13,7 +13,7 @@ module.exports = { PermissionsBitField.Flags.ManageMessages ] }, - "usage": "tictactoe (emoji) (emoji)", + "usage": "tictactoe [x_emoji(String)] [o_emoji(String)]", "function": { "command": {} } @@ -23,12 +23,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "tictactoe", "th": "โอเอกซ์" }, "description": module.exports.description, "description_localizations": { - "en-US": "Play tic-tac-toe with friends", "th": "เล่นโอเอกซ์กับเพื่อน" }, "options": [ @@ -46,7 +44,7 @@ module.exports.function.command = { }, { "type": 3, - "name": "xemoji", + "name": "x_emoji", "description": "Your emoji on the board", "description_localizations": { "th": "อีโมจิของคุณในกระดาน" @@ -57,7 +55,7 @@ module.exports.function.command = { }, { "type": 3, - "name": "oemoji", + "name": "o_emoji", "description": "The opponent emoji on the board", "description_localizations": { "th": "อีโมจิของฝั่งตรงข้ามในกระดาน" @@ -70,8 +68,8 @@ module.exports.function.command = { }, async execute(interaction) { const inputOpponent = interaction.options.getUser("opponent"); - const inputFirstEmoji = interaction.options.getString("xemoji") ?? "❌"; - const inputSecondEmoji = interaction.options.getString("oemoji") ?? "⭕"; + const inputFirstEmoji = interaction.options.getString("x_emoji") ?? "❌"; + const inputSecondEmoji = interaction.options.getString("o_emoji") ?? "⭕"; const getRandomString = (length) => { let result = ""; @@ -85,7 +83,7 @@ module.exports.function.command = { } const checkResult = (tie, gameData, player, author, member, midDuel, gameCollector, inputFirstEmoji, inputSecondEmoji, emojiTopLeft, emojiTopCenter, emojiTopRight, emojiMiddleLeft, emojiMiddleCenter, emojiMiddleRight, emojiBottomLeft, emojiBottomCenter, emojiBottomRight) => { const winsMessage = async () => { - await interaction.followUp(interaction.client.translate.commands.tictactoe.winner.reaplce("%s", gameData[player].member.username)) + await interaction.followUp(interaction.client.translate.commands.tictactoe.winner.replace("%s", gameData[player].member.username)) gameCollector.stop() midDuel.delete(author.id) midDuel.delete(member.id) @@ -140,18 +138,19 @@ module.exports.function.command = { } } - if (inputOpponent.bot) return await interaction.editReply(interaction.client.translate.commands.tictactoe.can_not_play_with_bot); - if (/([\uD800-\uDBFF][\uDC00-\uDFFF])/g.test(inputFirstEmoji)) return await interaction.editReply(interaction.client.translate.commands.tictactoe.need_one_emoji) - if (/([\uD800-\uDBFF][\uDC00-\uDFFF])/g.test(inputSecondEmoji)) return await interaction.editReply(interaction.client.translate.commands.tictactoe.need_one_emoji) + if (inputOpponent.bot) return await interaction.reply(interaction.client.translate.commands.tictactoe.can_not_play_with_bot); + if (/([\uD800-\uDBFF][\uDC00-\uDFFF])/g.test(inputFirstEmoji)) return await interaction.reply(interaction.client.translate.commands.tictactoe.need_one_emoji) + if (/([\uD800-\uDBFF][\uDC00-\uDFFF])/g.test(inputSecondEmoji)) return await interaction.reply(interaction.client.translate.commands.tictactoe.need_one_emoji) let player = 0; const midDuel = new Set() const author = interaction.user; const member = inputOpponent; - if (midDuel.has(author.id)) return await interaction.editReply(interaction.client.translate.commands.tictactoe.in_duel.replace("%s", member.id)) - if (midDuel.has(member.id)) return await interaction.editReply(interaction.client.translate.commands.tictactoe.in_another_duel.replace("%s", member.id)) - if (member.id === interaction.client.user.id) return await interaction.editReply(interaction.client.translate.commands.tictactoe.can_not_duel_with_me) + if (!member) return await interaction.reply(interaction.client.translate.commands.tictactoe.member_not_found); + if (midDuel.has(author.id)) return await interaction.reply(interaction.client.translate.commands.tictactoe.in_duel.replace("%s", member.id)) + if (midDuel.has(member.id)) return await interaction.reply(interaction.client.translate.commands.tictactoe.in_another_duel.replace("%s", member.id)) + if (member.id === interaction.client.user.id) return await interaction.reply(interaction.client.translate.commands.tictactoe.can_not_duel_with_me) const gameData = [ { "member": author, "emoji": inputFirstEmoji }, @@ -218,7 +217,7 @@ module.exports.function.command = { .setStyle(ButtonStyle.Secondary) .setLabel("~") - await interaction.editReply({ + await interaction.reply({ "embeds": [tictactoeEmbed], "components": [ { diff --git a/source/commands/games/together.js b/source/commands/games/together.js index d945e786..32ddd22c 100644 --- a/source/commands/games/together.js +++ b/source/commands/games/together.js @@ -1,5 +1,5 @@ const { PermissionsBitField } = require("discord.js"); -const fetch = require("node-fetch"); +const { post } = require("axios").default; module.exports = { "enable": true, @@ -13,7 +13,7 @@ module.exports = { PermissionsBitField.Flags.UseEmbeddedActivities ] }, - "usage": "together (channel: name, id)", + "usage": "together [channel]", "function": { "command": {} } @@ -24,7 +24,6 @@ module.exports.function.command = { "name": module.exports.name, "description": module.exports.description, "description_localizations": { - "en-US": "Run a specific emulator through the audio channel.", "th": "เรียกใช้อีมูเลเตอร์ Together ผ่านช่องเสียง" }, "options": [ @@ -148,11 +147,11 @@ module.exports.function.command = { ] }, async execute(interaction) { - const inputName = interaction.options.get("name").value; - const inputChannel = interaction.options.get("channel"); + const inputName = interaction.options.getString("name"); + const inputChannel = interaction.options.getChannel("channel"); const token = interaction.client.config.token; - let voiceChannel = interaction.member.voice.channel; + const voiceChannel = interaction.member.voice.channel; const apps = { "youtube": "880218394199220334", "youtubedev": "880218832743055411", @@ -179,34 +178,32 @@ module.exports.function.command = { }; if (!inputChannel) { - if (!voiceChannel) return await interaction.editReply(interaction.client.translate.commands.together.user_not_in_channel); + if (!voiceChannel) return await interaction.reply(interaction.client.translate.commands.together.user_not_in_channel); } else { - voiceChannel = interaction.guild.channels.cache.find(channels => (channels.id === inputChannel.value) || (channels.name === inputChannel.value)); - - if (!voiceChannel) return await interaction.editReply(interaction.client.translate.commands.together.voice_channel_not_found); + if (!inputChannel) return await interaction.reply(interaction.client.translate.commands.together.voice_channel_not_found); } - fetch("https://discord.com/api/v10/channels/" + voiceChannel.id + "/invites", { - "method": "POST", - "body": JSON.stringify({ + try { + const response = await post("https://discord.com/api/v10/channels/" + voiceChannel.id + "/invites", { "max_age": 86400, "max_uses": 0, "target_application_id": apps[inputName], "target_type": 2, "temporary": false, "validate": null, - }), - "headers": { - "Authorization": "Bot " + token, - "Content-Type": "application/json", - } - }) - .then((res) => res.json()) - .then(async (invite) => { - if (invite.error || !invite.code) return await interaction.editReply(interaction.client.translate.commands.together.can_not_open.replace("%s", inputName)); - if (Number(invite.code) === 50013) return await interaction.editReply(interaction.client.translate.commands.together.do_not_have_permission); - - await interaction.editReply(interaction.client.translate.commands.together.join_via_this_link + invite.code); + }, { + "headers": { + "Authorization": "Bot " + token, + "Content-Type": "application/json", + } }); + + if (response.data.error || !response.data.code) return await interaction.reply(interaction.client.translate.commands.together.can_not_open.replace("%s", inputName)); + if (Number(response.data.code) === 50013) return await interaction.reply(interaction.client.translate.commands.together.do_not_have_permission); + + await interaction.reply(interaction.client.translate.commands.together.join_via_this_link + response.data.code); + } catch (error) { + await interaction.reply(interaction.client.translate.commands.together.can_not_open.replace("%s", inputName)) + } } } \ No newline at end of file diff --git a/source/commands/information/anime.js b/source/commands/information/anime.js index 1dd36d04..b9d3fc4b 100644 --- a/source/commands/information/anime.js +++ b/source/commands/information/anime.js @@ -1,5 +1,5 @@ const { EmbedBuilder, PermissionsBitField } = require("discord.js"); -const fetch = require("node-fetch"); +const { get } = require("axios").default; module.exports = { "enable": true, @@ -12,7 +12,7 @@ module.exports = { PermissionsBitField.Flags.EmbedLinks ] }, - "usage": "anime ", + "usage": "anime ", "function": { "command": {} } @@ -22,12 +22,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "anime", "th": "อนิเมะ" }, "description": module.exports.description, "description_localizations": { - "en-US": "Search for anime or manga available on Kitsu.", "th": "ค้นหาอะนิเมะหรือมังงะที่มีอยู่ใน Kitsu" }, "options": [ @@ -46,7 +44,7 @@ module.exports.function.command = { ] }, async execute(interaction) { - const inputTitle = interaction.options.get("title").value; + const inputTitle = interaction.options.getString("title"); const titles = (data) => { const numTitle = []; @@ -67,87 +65,87 @@ module.exports.function.command = { return ["1", "2", "3", "4", "5"].includes(content.content); } - const baseURL = "https://kitsu.io/api/edge"; - const anime = "/anime?page[limit]=5&filter[text]=" + inputTitle; - const manga = "/manga?page[limit]=5&filter[text]=" + inputTitle; - const response = await fetch( - baseURL + anime || manga, - { + try { + const baseURL = "https://kitsu.io/api/edge"; + const anime = "/anime?page[limit]=5&filter[text]=" + inputTitle; + const manga = "/manga?page[limit]=5&filter[text]=" + inputTitle; + const response = await get(baseURL + (anime || manga), { "headers": { "Accept": "application/vnd.api+json", "Content-Type": "application/vnd.api+json" } - } - ); - const json = await response.json(); + }); - if (!json) return await interaction.editReply(interaction.client.translate.commands.anime.data_not_found); + const clientAvatarURL = interaction.client.user.avatarURL(); + const infoEmbed = new EmbedBuilder() + .setTitle("```" + inputTitle + "```") + .setDescription(interaction.client.translate.commands.anime.similar_stories) + .setColor(16083235) + .setFooter({ "text": interaction.client.translate.commands.anime.auto_cancel, "iconURL": clientAvatarURL }) + .setAuthor({ "name": "Kitsu", "url": "https://kitsu.io/", "iconURL": "https://kitsu.io/android-chrome-192x192-6b1404d91a423ea12340f41fc320c149.png" }) + .addFields( + [ + { + "name": interaction.client.translate.commands.anime.choose_now, + "value": titles(response.data.data) + } + ] + ); - const clientAvatarURL = interaction.client.user.avatarURL(); - const infoEmbed = new EmbedBuilder() - .setTitle("```" + inputTitle + "```") - .setDescription(interaction.client.translate.commands.anime.similar_stories) - .setColor(16083235) - .setFooter({ "text": interaction.client.translate.commands.anime.auto_cancel, "iconURL": clientAvatarURL }) - .setAuthor({ "name": "Kitsu", "url": "https://kitsu.io/", "iconURL": "https://kitsu.io/android-chrome-192x192-6b1404d91a423ea12340f41fc320c149.png" }) - .addFields([ - { - "name": interaction.client.translate.commands.anime.choose_now, - "value": titles(json.data) - } - ]); + await interaction.reply({ "embeds": [infoEmbed] }); - await interaction.editReply({ "embeds": [infoEmbed] }); + const collection = await interaction.channel.awaitMessages({ + filter, + "max": 1, + "time": 60000, + "errors": ["time"] + }); + const returnMessage = collection.first(); + const index = parseInt(returnMessage.content) - 1; - const collection = await interaction.channel.awaitMessages({ - filter, - "max": 1, - "time": 60000, - "errors": ["time"] - }); - const returnMessage = collection.first(); - const index = parseInt(returnMessage.content) - 1; + const attributes = response.data.data[index].attributes; + const trimmedSynopsis = attributes.synopsis.length >= 1015 ? attributes.synopsis.substring(0, 1015) + "..." : attributes.synopsis; - const attributes = json.data[index].attributes; - const trimmedSynopsis = attributes.synopsis.length >= 1015 ? attributes.synopsis.substring(0, 1015) + "..." : attributes.synopsis; - - infoEmbed.setColor(12601856) - .setFooter({ "text": interaction.client.translate.commands.anime.short_information, "iconURL": clientAvatarURL }) - .setFields( - [ - { - "name": interaction.client.translate.commands.anime.japan_name, - "value": attributes.titles.en_jp || interaction.client.translate.commands.anime.undefined - }, - { - "name": interaction.client.translate.commands.anime.english_name, - "value": attributes.titles.en || interaction.client.translate.commands.anime.undefined - }, - { - "name": interaction.client.translate.commands.anime.start_date, - "value": attributes.startDate, - "inline": true - }, - { - "name": interaction.client.translate.commands.anime.end_date, - "value": attributes.endDate || interaction.client.translate.commands.anime.in_progress, - "inline": true - }, - { - "name": interaction.client.translate.commands.anime.popularity_rank, - "value": attributes.popularityRank.toString(), - "inline": true - }, - { - "name": interaction.client.translate.commands.anime.link, - "value": "" - }, - { - "name": interaction.client.translate.commands.anime.synopsis, - "value": "```" + trimmedSynopsis + "```" - } - ] - ); - await interaction.editReply({ "embeds": [infoEmbed] }); + infoEmbed.setColor(12601856) + .setFooter({ "text": interaction.client.translate.commands.anime.short_information, "iconURL": clientAvatarURL }) + .setFields( + [ + { + "name": interaction.client.translate.commands.anime.japan_name, + "value": attributes.titles.en_jp || interaction.client.translate.commands.anime.undefined + }, + { + "name": interaction.client.translate.commands.anime.english_name, + "value": attributes.titles.en || interaction.client.translate.commands.anime.undefined + }, + { + "name": interaction.client.translate.commands.anime.start_date, + "value": attributes.startDate, + "inline": true + }, + { + "name": interaction.client.translate.commands.anime.end_date, + "value": attributes.endDate || interaction.client.translate.commands.anime.in_progress, + "inline": true + }, + { + "name": interaction.client.translate.commands.anime.popularity_rank, + "value": attributes.popularityRank.toString(), + "inline": true + }, + { + "name": interaction.client.translate.commands.anime.link, + "value": "" + }, + { + "name": interaction.client.translate.commands.anime.synopsis, + "value": "```" + trimmedSynopsis + "```" + } + ] + ); + await interaction.editReply({ "embeds": [infoEmbed] }); + } catch (error) { + await interaction.reply(interaction.client.translate.commands.anime.data_not_found); + } } } \ No newline at end of file diff --git a/source/commands/information/covid.js b/source/commands/information/covid.js index 7eb228f3..a1c2554f 100644 --- a/source/commands/information/covid.js +++ b/source/commands/information/covid.js @@ -1,5 +1,5 @@ const { EmbedBuilder, PermissionsBitField } = require("discord.js"); -const fetch = require("node-fetch"); +const { get } = require("axios").default; module.exports = { "enable": true, @@ -12,7 +12,7 @@ module.exports = { PermissionsBitField.Flags.EmbedLinks ] }, - "usage": "covid ", + "usage": "covid ", "function": { "command": {} } @@ -22,12 +22,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "covid", "th": "โควิด" }, "description": module.exports.description, "description_localizations": { - "en-US": "Get covid statistics for a country", "th": "สำหรวจสถิติโควิดในประเทศที่ต้องการ" }, "options": [ @@ -46,52 +44,54 @@ module.exports.function.command = { ] }, async execute(interaction) { - const inputCountry = interaction.options.get("country").value; + const inputCountry = interaction.options.getString("country"); - const response = await fetch("https://disease.sh/v3/covid-19/countries/" + inputCountry) + try { + const response = await get("https://disease.sh/v3/covid-19/countries/" + inputCountry) - if (response.status === 404) return await interaction.editReply(interaction.client.translate.commands.covid.country_not_found); - if (!response.ok) return await interaction.editReply(interaction.client.translate.commands.covid.backend_issue); + if (response.status === 404) return await interaction.reply(interaction.client.translate.commands.covid.country_not_found); + if (!response.data) return await interaction.reply(interaction.client.translate.commands.covid.backend_issue); - const data = await response.json(); + const date = new Date(response.updated); + const day = date.getDate(); + const month = date.getMonth() + 1; + const year = date.getFullYear(); + const hours = date.getHours(); + const minutes = "0" + date.getMinutes(); + const formattedTime = day + "/" + month + "/" + year + " " + interaction.client.translate.commands.covid.when + " " + hours + ':' + minutes.slice(-2); - const date = new Date(data.updated); - const day = date.getDate(); - const month = date.getMonth() + 1; - const year = date.getFullYear(); - const hours = date.getHours(); - const minutes = "0" + date.getMinutes(); - const formattedTime = day + "/" + month + "/" + year + " " + interaction.client.translate.commands.covid.when + " " + hours + ':' + minutes.slice(-2); + const clientFetch = await interaction.client.user.fetch(); + const clientColor = clientFetch.accentColor; + const covidEmbed = new EmbedBuilder() + .setTitle("🧫 Covid - %s".replace("%s", response.country)) + .setThumbnail(response.countryInfo.flag) + .setColor(clientColor) + .addFields( + [ + { "name": interaction.client.translate.commands.covid.cases_total, "value": response.cases.toLocaleString(), "inline": true }, + { "name": interaction.client.translate.commands.covid.cases_today, "value": response.todayCases.toLocaleString(), "inline": true }, + { "name": interaction.client.translate.commands.covid.deaths_total, "value": response.deaths.toLocaleString(), "inline": true }, + { "name": interaction.client.translate.commands.covid.deaths_today, "value": response.todayDeaths.toLocaleString(), "inline": true }, + { "name": interaction.client.translate.commands.covid.recovered, "value": response.recovered.toLocaleString(), "inline": true }, + { "name": interaction.client.translate.commands.covid.active, "value": response.active.toLocaleString(), "inline": true }, + { "name": interaction.client.translate.commands.covid.critical_stage, "value": response.critical.toLocaleString(), "inline": true }, + { "name": interaction.client.translate.commands.covid.cases_per_one_million, "value": response.casesPerOneMillion.toLocaleString(), "inline": true }, + { "name": interaction.client.translate.commands.covid.tests, "value": response.tests.toLocaleString(), "inline": true }, + { "name": interaction.client.translate.commands.covid.tests_per_one_million, "value": response.testsPerOneMillion.toLocaleString(), "inline": true }, + { "name": interaction.client.translate.commands.covid.population, "value": response.population.toLocaleString(), "inline": true }, + { "name": interaction.client.translate.commands.covid.one_case_per_people, "value": response.oneCasePerPeople.toLocaleString(), "inline": true }, + { "name": interaction.client.translate.commands.covid.one_death_per_people, "value": response.oneDeathPerPeople.toLocaleString(), "inline": true }, + { "name": interaction.client.translate.commands.covid.one_test_per_people, "value": response.oneTestPerPeople.toLocaleString(), "inline": true }, + { "name": interaction.client.translate.commands.covid.active_per_one_million, "value": response.activePerOneMillion.toLocaleString(), "inline": true }, + { "name": interaction.client.translate.commands.covid.recovered_per_one_million, "value": response.recoveredPerOneMillion.toLocaleString(), "inline": true }, + { "name": interaction.client.translate.commands.covid.critical_per_one_million, "value": response.criticalPerOneMillion.toLocaleString(), "inline": true } + ] + ) + .setFooter({ "text": interaction.client.translate.commands.covid.updated_on.replace("%s", formattedTime) }); - const clientFetch = await interaction.client.user.fetch(); - const clientColor = clientFetch.accentColor; - const covidEmbed = new EmbedBuilder() - .setTitle("🧫 Covid - %s".replace("%s", data.country)) - .setThumbnail(data.countryInfo.flag) - .setColor(clientColor) - .addFields( - [ - { "name": interaction.client.translate.commands.covid.cases_total, "value": data.cases.toLocaleString(), "inline": true }, - { "name": interaction.client.translate.commands.covid.cases_today, "value": data.todayCases.toLocaleString(), "inline": true }, - { "name": interaction.client.translate.commands.covid.deaths_total, "value": data.deaths.toLocaleString(), "inline": true }, - { "name": interaction.client.translate.commands.covid.deaths_today, "value": data.todayDeaths.toLocaleString(), "inline": true }, - { "name": interaction.client.translate.commands.covid.recovered, "value": data.recovered.toLocaleString(), "inline": true }, - { "name": interaction.client.translate.commands.covid.active, "value": data.active.toLocaleString(), "inline": true }, - { "name": interaction.client.translate.commands.covid.critical_stage, "value": data.critical.toLocaleString(), "inline": true }, - { "name": interaction.client.translate.commands.covid.cases_per_one_million, "value": data.casesPerOneMillion.toLocaleString(), "inline": true }, - { "name": interaction.client.translate.commands.covid.tests, "value": data.tests.toLocaleString(), "inline": true }, - { "name": interaction.client.translate.commands.covid.tests_per_one_million, "value": data.testsPerOneMillion.toLocaleString(), "inline": true }, - { "name": interaction.client.translate.commands.covid.population, "value": data.population.toLocaleString(), "inline": true }, - { "name": interaction.client.translate.commands.covid.one_case_per_people, "value": data.oneCasePerPeople.toLocaleString(), "inline": true }, - { "name": interaction.client.translate.commands.covid.one_death_per_people, "value": data.oneDeathPerPeople.toLocaleString(), "inline": true }, - { "name": interaction.client.translate.commands.covid.one_test_per_people, "value": data.oneTestPerPeople.toLocaleString(), "inline": true }, - { "name": interaction.client.translate.commands.covid.active_per_one_million, "value": data.activePerOneMillion.toLocaleString(), "inline": true }, - { "name": interaction.client.translate.commands.covid.recovered_per_one_million, "value": data.recoveredPerOneMillion.toLocaleString(), "inline": true }, - { "name": interaction.client.translate.commands.covid.critical_per_one_million, "value": data.criticalPerOneMillion.toLocaleString(), "inline": true } - ] - ) - .setFooter({ "text": interaction.client.translate.commands.covid.updated_on.replace("%s", formattedTime) }); - - await interaction.editReply({ "embeds": [covidEmbed] }); + await interaction.reply({ "embeds": [covidEmbed] }); + } catch (error) { + await interaction.reply(interaction.client.translate.commands.covid.country_not_found); + } } } \ No newline at end of file diff --git a/source/commands/information/guild.js b/source/commands/information/guild.js index a3a8e7c0..f7e34501 100644 --- a/source/commands/information/guild.js +++ b/source/commands/information/guild.js @@ -8,7 +8,7 @@ module.exports = { "permissions": { "client": [PermissionsBitField.Flags.SendMessages] }, - "usage": "guild (info)", + "usage": "guild [info(String)]", "function": { "command": {} } @@ -18,12 +18,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "guild", - "th": "สมาคม" + "th": "กิลด์" }, "description": module.exports.description, "description_localizations": { - "en-US": "Get information about the server.", "th": "รับข้อมูลเกี่ยวกับเซิร์ฟเวอร์" }, "options": [ @@ -42,7 +40,7 @@ module.exports.function.command = { ] }, async execute(interaction) { - const inputInfo = interaction.options.get("info"); + const inputInfo = interaction.options.getString("info") ?? ""; const dateFormat = (data) => { if (!data) return; @@ -129,7 +127,7 @@ module.exports.function.command = { const embed = new EmbedBuilder() .setTitle(interaction.client.translate.commands.guild.server_info) .setDescription(interaction.client.translate.commands.guild.server_info_description) - .setColor("BLUE") + .setColor("Blue") .setTimestamp() .setFooter({ "text": interaction.client.translate.commands.guild.info_date, "iconURL": guildIcon || "" }) .setThumbnail(guildIcon || "") @@ -224,19 +222,19 @@ module.exports.function.command = { ]; if (inputInfo) { - if (info.includes(inputInfo.value)) { + if (info.includes(inputInfo)) { for (let i = 0; i < info.length; i++) { - if (inputInfo.value === info[i]) { + if (inputInfo === info[i]) { embed.addFields(infoList[i]); - await interaction.editReply({ "embeds": [embed] }); + await interaction.reply({ "embeds": [embed] }); } } } else { - await interaction.editReply(interaction.client.translate.commands.guild.specific_use.replace("%s", info.join(", "))); + await interaction.reply(interaction.client.translate.commands.guild.specific_use.replace("%s", info.join(", "))); } } else { embed.addFields(Array.from(infoList).slice(0, 25)); - await interaction.editReply({ "embeds": [embed] }); + await interaction.reply({ "embeds": [embed] }); } } } \ No newline at end of file diff --git a/source/commands/information/leveling.js b/source/commands/information/leveling.js index e22e5a2e..008ee1b8 100644 --- a/source/commands/information/leveling.js +++ b/source/commands/information/leveling.js @@ -9,7 +9,7 @@ module.exports = { "permissions": { "client": [PermissionsBitField.Flags.SendMessages] }, - "usage": "leveling (member: id, username, tag)", + "usage": "leveling [member]", "function": { "command": {} } @@ -19,12 +19,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "leveling", "th": "เลเวล" }, "description": module.exports.description, "description_localizations": { - "en-US": "See information about your level.", "th": "ดูข้อมูลเกี่ยวกับเลเวลของคุณ" }, "options": [ @@ -43,28 +41,24 @@ module.exports.function.command = { ] }, async execute(interaction) { - const inputMember = interaction.options.get("member"); + const inputMember = interaction.options.getMember("member") ?? ""; - let authorAvatar = interaction.user.displayAvatarURL(); - let authorFetch = await interaction.user.fetch(); - let authorID = interaction.user.id; + let author = interaction.user; + let authorAvatar = author.displayAvatarURL(); + let authorFetch = await author.fetch(); let memberBot = false; if (inputMember) { - const member = interaction.guild.members.cache.find(members => (members.user.username === inputMember.value) || (members.user.id === inputMember.value) || (members.user.tag === inputMember.value)); - - if (!member) return await interaction.editReply(interaction.client.translate.commands.leveling.can_not_find_user); - - authorAvatar = member.user.avatarURL(); - authorFetch = await member.user.fetch(); - authorID = member.user.id; - memberBot = member.user.bot; + author = member.user; + authorAvatar = author.avatarURL(); + authorFetch = await author.fetch(); + memberBot = author.bot; } - if (memberBot) return await interaction.editReply(interaction.client.translate.commands.leveling.bot_do_not_have_level); + if (memberBot) return await interaction.reply(interaction.client.translate.commands.leveling.bot_do_not_have_level); - const data = await levelSystem(interaction.client, interaction, "GET", authorID); + const data = await levelSystem(interaction.client, interaction, "GET", { "member": author }); - if (!data) return await interaction.editReply(interaction.client.translate.commands.leveling.user_no_data); + if (!data) return await interaction.reply(interaction.client.translate.commands.leveling.user_no_data); const exp = data.exp; const level = data.level; @@ -88,8 +82,6 @@ module.exports.function.command = { ] ); - await interaction.editReply({ - "embeds": [levelingEmbed] - }); + await interaction.reply({ "embeds": [levelingEmbed] }); } } \ No newline at end of file diff --git a/source/commands/information/status.js b/source/commands/information/status.js index f128a23a..f38a8252 100644 --- a/source/commands/information/status.js +++ b/source/commands/information/status.js @@ -8,7 +8,7 @@ module.exports = { "permissions": { "client": [PermissionsBitField.Flags.SendMessages] }, - "usage": "status ", + "usage": "status ", "function": { "command": {} } @@ -18,12 +18,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "status", "th": "สถานะ" }, "description": module.exports.description, "description_localizations": { - "en-US": "Check the status of all members within the server", "th": "ตรวจสอบสถานะของสมาชิกทั้งหมดภายในเซิร์ฟเวอร์" }, "options": [ @@ -72,7 +70,7 @@ module.exports.function.command = { ] }, async execute(interaction) { - const inputType = interaction.options.get("type").value; + const inputType = interaction.options.getString("type"); const guildIcon = interaction.guild.iconURL(); const statusEmbed = new EmbedBuilder() @@ -85,36 +83,28 @@ module.exports.function.command = { statusEmbed.setDescription(interaction.client.translate.commands.status.online_status.replace("%s", onlineCount)) .setColor("Green"); - await interaction.editReply({ - "embeds": [statusEmbed] - }); + await interaction.reply({ "embeds": [statusEmbed] }); break; case "offline": const offlineCount = interaction.guild.members.cache.filter(members => members.presence ? members.presence.status === "offline" : "offline").size; statusEmbed.setDescription(interaction.client.translate.commands.status.offline_status.replace("%s", offlineCount)) .setColor("Grey"); - await interaction.editReply({ - "embeds": [statusEmbed] - }); + await interaction.reply({ "embeds": [statusEmbed] }); break; case "idle": const idleCount = interaction.guild.members.cache.filter(members => members.presence ? members.presence.status === "idle" : null).size; statusEmbed.setDescription(interaction.client.translate.commands.status.idle_status.replace("%s", idleCount)) .setColor("Yellow"); - await interaction.editReply({ - "embeds": [statusEmbed] - }); + await interaction.reply({ "embeds": [statusEmbed] }); break; case "dnd": const dndCount = interaction.guild.members.cache.filter(members => members.presence ? members.presence.status === "dnd" : null).size; statusEmbed.setDescription(interaction.client.translate.commands.status.dnd_status.replace("%s", dndCount)) .setColor("Red"); - await interaction.editReply({ - "embeds": [statusEmbed] - }); + await interaction.reply({ "embeds": [statusEmbed] }); break; } } diff --git a/source/commands/information/user.js b/source/commands/information/user.js index 67f5d14e..2210c082 100644 --- a/source/commands/information/user.js +++ b/source/commands/information/user.js @@ -9,7 +9,7 @@ module.exports = { "permissions": { "client": [PermissionsBitField.Flags.SendMessages] }, - "usage": "user (info) (member)", + "usage": "user [info] [member]", "function": { "command": {} } @@ -19,12 +19,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "user", "th": "ผู้ใช้" }, "description": module.exports.description, "description_localizations": { - "en-US": "Get your user information", "th": "รับข้อมูลผู้ใช้ของคุณ" }, "options": [ @@ -134,8 +132,8 @@ module.exports.function.command = { ] }, async execute(interaction) { - const inputInfo = interaction.options.get("info"); - const inputMember = interaction.options.get("member"); + const inputInfo = interaction.options.getString("info") ?? ""; + const inputMember = interaction.options.getMember("member") ?? ""; const dateFormat = (data) => { if (!data) return; @@ -186,32 +184,31 @@ module.exports.function.command = { let tag = interaction.user.tag || interaction.client.translate.commands.user.unknown; let username = interaction.user.username || interaction.client.translate.commands.user.unknown; - const usersSnapshot = interaction.client.api.apps.discord.guilds[interaction.guild.id].data.users + const usersSnapshot = interaction.client.api.users const usersRef = child(child(ref(getDatabase(), "Shioru/apps/discord/guilds"), interaction.guild.id), "data/users"); const clientUsername = interaction.client.user.username; const clientAvatarURL = interaction.client.user.avatarURL(); const embed = new EmbedBuilder() .setTitle(interaction.client.translate.commands.user.user_info) .setDescription(interaction.client.translate.commands.user.user_info_description) - .setColor("BLUE") + .setColor("Blue") .setTimestamp() .setFooter({ "text": interaction.client.translate.commands.user.info_date, "iconURL": avatar }) .setThumbnail(avatar) .setAuthor({ "name": clientUsername, "iconURL": clientAvatarURL }); - const member = interaction.guild.members.cache.find(members => (members.user.username === (inputMember ? inputMember.value : "")) || (members.user.id === (inputMember ? inputMember.value : "")) || (members.user.tag === (inputMember ? inputMember.value : ""))); - if (member) { - avatar = member.user.avatarURL() || interaction.client.translate.commands.user.unknown; - bot = member.user.bot ? interaction.client.translate.commands.user.yes : interaction.client.translate.commands.user.none; - createdAt = member.user.createdAt.toString() || interaction.client.translate.commands.user.unknown; - createdTimestamp = dateFormat(member.user.createdTimestamp) || interaction.client.translate.commands.user.unknown; - defaultAvatarURL = member.user.defaultAvatarURL || interaction.client.translate.commands.user.unknown; - discriminator = member.user.discriminator || interaction.client.translate.commands.user.unknown; - id = member.user.id || interaction.client.translate.commands.user.unknown; - partial = member.user.partial ? interaction.client.translate.commands.user.yes : interaction.client.translate.commands.user.none; - system = member.user.system ? interaction.client.translate.commands.user.yes : interaction.client.translate.commands.user.none; - tag = member.user.tag || interaction.client.translate.commands.user.unknown; - username = member.user.username || interaction.client.translate.commands.user.unknown; + if (inputMember) { + avatar = inputMember.user.avatarURL() || interaction.client.translate.commands.user.unknown; + bot = inputMember.user.bot ? interaction.client.translate.commands.user.yes : interaction.client.translate.commands.user.none; + createdAt = inputMember.user.createdAt.toString() || interaction.client.translate.commands.user.unknown; + createdTimestamp = dateFormat(inputMember.user.createdTimestamp) || interaction.client.translate.commands.user.unknown; + defaultAvatarURL = inputMember.user.defaultAvatarURL || interaction.client.translate.commands.user.unknown; + discriminator = inputMember.user.discriminator || interaction.client.translate.commands.user.unknown; + id = inputMember.user.id || interaction.client.translate.commands.user.unknown; + partial = inputMember.user.partial ? interaction.client.translate.commands.user.yes : interaction.client.translate.commands.user.none; + system = inputMember.user.system ? interaction.client.translate.commands.user.yes : interaction.client.translate.commands.user.none; + tag = inputMember.user.tag || interaction.client.translate.commands.user.unknown; + username = inputMember.user.username || interaction.client.translate.commands.user.unknown; } const info = [ @@ -243,55 +240,51 @@ module.exports.function.command = { if (inputInfo) { if (inputMember) { - if (member) { - if (bot) { - embed.setFooter({ "text": interaction.client.translate.commands.user.info_date, "iconURL": avatar }) - .setThumbnail(avatar); + if (bot) { + embed.setFooter({ "text": interaction.client.translate.commands.user.info_date, "iconURL": avatar }) + .setThumbnail(avatar); - for (let i = 0; i < info.length; i++) { - if (inputInfo.value === info[i]) { - embed.addFields(infoList[i]); - await interaction.editReply({ "embeds": [embed] }); - } + for (let i = 0; i < info.length; i++) { + if (inputInfo === info[i]) { + embed.addFields(infoList[i]); + await interaction.reply({ "embeds": [embed] }); } - } else { - const snapshot = usersSnapshot[id].access + } + } else { + const snapshot = usersSnapshot[id].access - if (snapshot) { - if (snapshot.info) { - embed.setFooter({ "text": interaction.client.translate.commands.user.info_date, "iconURL": avatar }) - .setThumbnail(avatar); + if (snapshot) { + if (snapshot.info) { + embed.setFooter({ "text": interaction.client.translate.commands.user.info_date, "iconURL": avatar }) + .setThumbnail(avatar); - for (let i = 0; i < info.length; i++) { - if (inputInfo.value === info[i]) { - embed.addFields(infoList[i]); - await interaction.editReply({ "embeds": [embed] }); - } + for (let i = 0; i < info.length; i++) { + if (inputInfo === info[i]) { + embed.addFields(infoList[i]); + await interaction.reply({ "embeds": [embed] }); } - } else { - await interaction.editReply(interaction.client.translate.commands.user.info.not_allowed); } } else { - set(child(child(usersRef, id), "access"), { - "avatar": false, - "info": false, - "uid": false - }).then(() => { - module.exports.interaction.execute(interaction); - }); + await interaction.reply(interaction.client.translate.commands.user.info.not_allowed); } + } else { + set(child(child(usersRef, id), "access"), { + "avatar": false, + "info": false, + "uid": false + }).then(() => { + module.exports.interaction.execute(interaction); + }); } - } else { - await interaction.editReply(interaction.client.translate.commands.user.can_not_find_user.replace("%s", interaction.client.config.owner)); } } else { - if (member) { + if (inputMember) { if (bot) { embed.setFooter({ "text": interaction.client.translate.commands.user.info_date, "iconURL": avatar }) .setThumbnail(avatar) .addFields(Array.from(infoList)); - await interaction.editReply({ "embeds": [embed] }); + await interaction.reply({ "embeds": [embed] }); } else { const snapshot = usersSnapshot[id].access @@ -301,9 +294,9 @@ module.exports.function.command = { .setThumbnail(avatar) .addFields(Array.from(infoList)); - await interaction.editReply({ "embeds": [embed] }); + await interaction.reply({ "embeds": [embed] }); } else { - await interaction.editReply(interaction.client.translate.commands.user.info.not_allowed); + await interaction.reply(interaction.client.translate.commands.user.info.not_allowed); } } else { set(child(child(usersRef, id), "access"), { @@ -317,51 +310,47 @@ module.exports.function.command = { } } else { for (let i = 0; i < info.length; i++) { - if (inputInfo.value === info[i]) { + if (inputInfo === info[i]) { embed.addFields(infoList[i]); - await interaction.editReply({ "embeds": [embed] }); + await interaction.reply({ "embeds": [embed] }); } } } } } else { if (inputMember) { - if (member) { - if (bot) { - embed.setFooter({ "text": interaction.client.translate.commands.user.info_date, "iconURL": avatar }) - .setThumbnail(avatar) - .addFields(Array.from(infoList)); + if (bot) { + embed.setFooter({ "text": interaction.client.translate.commands.user.info_date, "iconURL": avatar }) + .setThumbnail(avatar) + .addFields(Array.from(infoList)); - await interaction.editReply({ "embeds": [embed] }); - } else { - const snapshot = usersSnapshot[id].access + await interaction.reply({ "embeds": [embed] }); + } else { + const snapshot = usersSnapshot[id].access - if (snapshot) { - if (snapshot.info) { - embed.setFooter({ "text": interaction.client.translate.commands.user.info_date, "iconURL": avatar }) - .setThumbnail(avatar) - .addFields(Array.from(infoList)); + if (snapshot) { + if (snapshot.info) { + embed.setFooter({ "text": interaction.client.translate.commands.user.info_date, "iconURL": avatar }) + .setThumbnail(avatar) + .addFields(Array.from(infoList)); - await interaction.editReply({ "embeds": [embed] }); - } else { - await interaction.editReply(interaction.client.translate.commands.user.info.not_allowed); - } + await interaction.reply({ "embeds": [embed] }); } else { - set(child(child(usersRef, id), "access"), { - "avatar": false, - "info": false, - "uid": false - }).then(() => { - module.exports.interaction.execute(interaction); - }); + await interaction.reply(interaction.client.translate.commands.user.info.not_allowed); } + } else { + set(child(child(usersRef, id), "access"), { + "avatar": false, + "info": false, + "uid": false + }).then(() => { + module.exports.interaction.execute(interaction); + }); } - } else { - await interaction.editReply(interaction.client.translate.commands.user.can_not_find_user.replace("%s", interaction.client.config.owner)); } } else { embed.addFields(Array.from(infoList)); - await interaction.editReply({ "embeds": [embed] }); + await interaction.reply({ "embeds": [embed] }); } } } diff --git a/source/commands/information/weather.js b/source/commands/information/weather.js index 1a31681a..14347108 100644 --- a/source/commands/information/weather.js +++ b/source/commands/information/weather.js @@ -10,7 +10,7 @@ module.exports = { "permissions": { "client": [PermissionsBitField.Flags.SendMessages] }, - "usage": "weather ", + "usage": "weather [degree_type]", "function": { "command": {} } @@ -20,12 +20,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "weather", "th": "สภาพอากาศ" }, "description": module.exports.description, "description_localizations": { - "en-US": "See today's weather in each area.", "th": "ดูสภาพอากาศของวันนี้ในแต่ละพื้นที่ที่ต้องการ" }, "options": [ @@ -40,17 +38,48 @@ module.exports.function.command = { "th": "พื้นที่ที่คุณต้องการทราบสภาพอากาศ" }, "required": true + }, + { + "type": 3, + "name": "degree_type", + "name_localizations": { + "th": "หน่วยวัด" + }, + "description": "Unit of measure for weather conditions.", + "description_localizations": { + "th": "หน่วยวัดของสภาพอากาศ" + }, + "required": false, + "choices": [ + { + "name": "Celsius", + "name_localizations": { + "th": "เซลเซียส" + }, + "value": "C" + }, + { + "name": "Fahrenheit", + "name_localizations": { + "th": "ฟาเรนไฮต์" + }, + "value": "F" + } + ] } ] }, async execute(interaction) { - const inputArea = interaction.options.get("area").value; + await interaction.deferReply(); + + const inputArea = interaction.options.getString("area"); + const inputDegreeType = interaction.options.getString("degree_type"); find({ "search": inputArea, - "degreeType": "C" + "degreeType": inputDegreeType }, async (error, result) => { - if (error) return catchError(interaction.client, interaction, module.exports.help.name, error); + if (error) return catchError(interaction.client, interaction, module.exports.name, error); if (!result) return await interaction.editReply(interaction.client.translate.commands.weather.no_result_found); const city = result[0]; diff --git a/source/commands/manager/ban.js b/source/commands/manager/ban.js index 250d74d2..1834efdb 100644 --- a/source/commands/manager/ban.js +++ b/source/commands/manager/ban.js @@ -12,7 +12,7 @@ module.exports = { PermissionsBitField.Flags.BanMembers ] }, - "usage": "ban (days) (reason)", + "usage": "ban [days(Number)] [reason(String)]", "function": { "command": {} } @@ -22,12 +22,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "ban", "th": "แบน" }, "description": module.exports.description, "description_localizations": { - "en-US": "Ban members within the server.", "th": "แบนสมาชิกภายในเซิร์ฟเวอร์" }, "options": [ @@ -72,39 +70,33 @@ module.exports.function.command = { ] }, async execute(interaction) { - const inputMember = interaction.options.get("member").value; - let inputDays = interaction.options.get("days"); - let inputReason = interaction.options.get("reason"); + const inputMember = interaction.options.getMember("member"); + const inputDays = interaction.options.getNumber("days") ?? 0; + const inputReason = interaction.options.getString("reason") ?? ""; - const member = interaction.guild.members.cache.find(members => (members.user.username === inputMember) || (members.user.id === inputMember) || (members.user.tag === inputMember)); + const member = await interaction.guild.members.fetch(inputMember.id); + const banned = await interaction.guild.bans.fetch(inputMember.id); if (!member) return await interaction.editReply(interaction.client.translate.commands.ban.user_not_found); + if (!banned) return await interaction.reply(interaction.client.translate.commands.ban.member_has_banned); - const banned = await interaction.guild.bans.fetch(); - - if (banned.length > 0 && banned.map((user => user.user.id === member.user.id))) { - return await interaction.editReply(interaction.client.translate.commands.ban.member_has_banned) - } - - const memberPosition = member.roles.highest.position; + const memberPosition = inputMember.roles.highest.position; const authorPosition = interaction.member.roles.highest.position; - if (authorPosition < memberPosition) return await interaction.editReply(interaction.client.translate.commands.ban.members_have_a_higher_role); - if (!member.bannable) return await interaction.editReply(interaction.client.translate.commands.ban.members_have_a_higher_role_than_me); - if (!inputDays) inputDays = 0; - if (!inputReason) inputReason = ""; + if (authorPosition < memberPosition) return await interaction.reply(interaction.client.translate.commands.ban.members_have_a_higher_role); + if (!inputMember.bannable) return await interaction.reply(interaction.client.translate.commands.ban.members_have_a_higher_role_than_me); - const ban = await interaction.guild.bans.create(member, { + const baned = await interaction.guild.bans.create(member, { "deleteMessageDays": inputDays, "reason": inputReason }); const authorUsername = interaction.user.username; - const memberAvatar = ban.user.avatarURL(); - const memberUsername = ban.user.username; + const memberAvatar = baned.user.avatarURL(); + const memberUsername = baned.user.username; let embedTitle = interaction.client.translate.commands.ban.banned_for_time.replace("%s1", memberUsername).replace("%s2", inputDays); - if (inputDays === 0) embedTitle = interaction.client.translate.commands.ban.permanently_banned.replace("%s", memberUsername); + if (!inputDays) embedTitle = interaction.client.translate.commands.ban.permanently_banned.replace("%s", memberUsername); if (!inputReason) inputReason = interaction.client.translate.commands.ban.no_reason; const banEmbed = new EmbedBuilder() @@ -114,8 +106,6 @@ module.exports.function.command = { .setTimestamp() .setThumbnail(memberAvatar); - await interaction.editReply({ - "embeds": [banEmbed] - }); + await interaction.reply({ "embeds": [banEmbed] }); } }; \ No newline at end of file diff --git a/source/commands/manager/kick.js b/source/commands/manager/kick.js index 265a4f0e..d82dc377 100644 --- a/source/commands/manager/kick.js +++ b/source/commands/manager/kick.js @@ -12,22 +12,20 @@ module.exports = { PermissionsBitField.Flags.KickMembers ] }, - "usage": "kick (reason)", - "function": { - "command": {} - } + "usage": "kick [reason(String)]", + "function": { + "command": {} + } }; module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "kick", "th": "เตะ" }, "description": module.exports.description, "description_localizations": { - "en-US": "Kick members from the server.", "th": "เตะสมาชิกจากออกเซิร์ฟเวอร์" }, "options": [ @@ -58,23 +56,20 @@ module.exports.function.command = { ] }, async execute(interaction) { - const inputMember = interaction.options.get("member").value; - let inputReason = interaction.options.get("reason"); + const inputMember = interaction.options.getMember("member"); + const inputReason = interaction.options.getString("reason") ?? ""; - const member = interaction.guild.members.cache.find(members => (members.user.username === inputMember) || (members.user.id === inputMember) || (members.user.tag === inputMember)); + const member = await interaction.guild.members.fetch(inputMember.id); if (!member) return await interaction.editReply(interaction.client.translate.commands.kick.can_not_find_user); - const memberPosition = member.roles.highest.position; + const memberPosition = inputMember.roles.highest.position; const authorPosition = interaction.member.roles.highest.position; - if (authorPosition < memberPosition) return await interaction.editReply(interaction.client.translate.commands.kick.members_have_a_higher_role); - if (!member.kickable) return await interaction.editReply(interaction.client.translate.commands.kick.members_have_a_higher_role_than_me); - if (!inputReason) inputReason = ""; + if (authorPosition < memberPosition) return await interaction.reply(interaction.client.translate.commands.kick.members_have_a_higher_role); + if (!inputMember.kickable) return await interaction.reply(interaction.client.translate.commands.kick.members_have_a_higher_role_than_me); - const kicked = await member.kick({ - "reason": inputReason - }); + const kicked = await inputMember.kick({ "reason": inputReason }); const authorUsername = interaction.user.username; const memberAvatar = kicked.user.avatarURL(); const memberUsername = kicked.user.username; @@ -88,8 +83,6 @@ module.exports.function.command = { .setTimestamp() .setThumbnail(memberAvatar); - await interaction.editReply({ - "embeds": [kickEmbed] - }); + await interaction.reply({ "embeds": [kickEmbed] }); } }; \ No newline at end of file diff --git a/source/commands/manager/purge.js b/source/commands/manager/purge.js index f894a195..9bb1ac6b 100644 --- a/source/commands/manager/purge.js +++ b/source/commands/manager/purge.js @@ -17,22 +17,20 @@ module.exports = { PermissionsBitField.Flags.ManageMessages ] }, - "usage": "purge ", - "function": { - "command": {} - } + "usage": "purge ", + "function": { + "command": {} + } }; module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "purge", "th": "ล้าง" }, "description": module.exports.description, "description_localizations": { - "en-US": "Delete a lot of messages", "th": "ลบข้อความจำนวนมาก" }, "options": [ @@ -53,20 +51,20 @@ module.exports.function.command = { ] }, async execute(interaction) { - let messageCount = interaction.options.get("amount").value; + const inputAmount = interaction.options.getNumber("amount"); + + const previousMessages = await interaction.channel.messages.fetch({ "limit": 1 }); - interaction.channel.messages.fetch({ - "limit": 1 - }).then((previousMessages) => { - interaction.channel.messages.fetch({ - "limit": messageCount, + try { + const messages = await interaction.channel.messages.fetch({ + "limit": inputAmount, "before": previousMessages.first().id - }).then(async (messages) => { - await interaction.channel.bulkDelete(messages, true); - await interaction.editReply(interaction.client.translate.commands.purge.message_cleared.replace("%s", messages.size)); - }).catch((error) => { - catchError(interaction.client, interaction, module.exports.name, error); }); - }); + + await interaction.channel.bulkDelete(messages, true); + await interaction.reply(interaction.client.translate.commands.purge.message_cleared.replace("%s", messages.size)); + } catch (error) { + catchError(interaction.client, interaction, module.exports.name, error); + } } }; \ No newline at end of file diff --git a/source/commands/manager/unban.js b/source/commands/manager/unban.js index 9e3421b7..9bbe6c11 100644 --- a/source/commands/manager/unban.js +++ b/source/commands/manager/unban.js @@ -12,7 +12,7 @@ module.exports = { PermissionsBitField.Flags.BanMembers ] }, - "usage": "unban (reason)", + "usage": "unban [reason(String)]", "function": { "command": {} } @@ -22,17 +22,15 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "unban", "th": "ปลดแบน" }, "description": module.exports.description, "description_localizations": { - "en-US": "Stop banning members who are banned in the server.", "th": "ปลดแบนสมาชิกที่ถูกแบนในเซิร์ฟเวอร์" }, "options": [ { - "type": 6, + "type": 3, "name": "member", "name_localizations": { "th": "สมาชิก" @@ -58,40 +56,34 @@ module.exports.function.command = { ] }, async execute(interaction) { - const inputMember = interaction.options.get("member").value; - let inputReason = interaction.options.get("reason"); + const inputMember = interaction.options.getString("member"); + const inputReason = interaction.options.getString("reason") ?? ""; - const banned = await interaction.guild.bans.fetch(); + const banned = await interaction.guild.bans.fetch(inputMember.id); - if (banned.length <= 0) return await interaction.editReply(interaction.client.translate.commands.unban.no_one_gets_banned); + if (banned.length <= 0) return await interaction.reply(interaction.client.translate.commands.unban.no_one_gets_banned); const bannedUser = banned.find(members => (members.user.username === inputMember) || (members.user.id === inputMember) || (members.user.tag === inputMember)); - if (!bannedUser) return await interaction.editReply(interaction.client.translate.commands.unban.this_user_not_banned); - if (!inputReason) inputReason = ""; + if (!bannedUser) return await interaction.reply(interaction.client.translate.commands.unban.this_user_not_banned); + + await interaction.guild.bans.remove(bannedUser.user, { "reason": inputReason }); - interaction.guild.bans.remove(bannedUser.user, { - "reason": inputReason - }).then(async () => { - const authorUsername = interaction.user.username; - const memberUsername = bannedUser.user.username; - const memberID = bannedUser.user.id; - const memberAvatar = bannedUser.user.avatar; - const memberAvatarURL = "https://cdn.discordapp.com/avatars/" + memberID + "/" + memberAvatar + ".png"; - const time = new Date().toISOString(); + const authorUsername = interaction.user.username; + const memberUsername = bannedUser.user.username; + const memberID = bannedUser.user.id; + const memberAvatar = bannedUser.user.avatar; + const memberAvatarURL = "https://cdn.discordapp.com/avatars/" + memberID + "/" + memberAvatar + ".png"; - if (!inputReason) inputReason = interaction.client.translate.commands.unban.no_reason; + if (!inputReason) inputReason = interaction.client.translate.commands.unban.no_reason; - const unbanEmbed = new EmbedBuilder() - .setTitle(interaction.client.translate.commands.unban.user_has_been_unbanned.replace("%s", memberUsername)) - .setDescription(interaction.client.translate.commands.unban.reason_for_unban.replace("%s1", authorUsername).replace("%s2", inputReason)) - .setColor("Green") - .setTimestamp() - .setThumbnail(memberAvatarURL); + const unbanEmbed = new EmbedBuilder() + .setTitle(interaction.client.translate.commands.unban.user_has_been_unbanned.replace("%s", memberUsername)) + .setDescription(interaction.client.translate.commands.unban.reason_for_unban.replace("%s1", authorUsername).replace("%s2", inputReason)) + .setColor("Green") + .setTimestamp() + .setThumbnail(memberAvatarURL); - await interaction.editReply({ - "embeds": [unbanEmbed] - }); - }); + await interaction.reply({ "embeds": [unbanEmbed] }); } }; \ No newline at end of file diff --git a/source/commands/me/about.js b/source/commands/me/about.js index dff18ce6..beeaf682 100644 --- a/source/commands/me/about.js +++ b/source/commands/me/about.js @@ -18,12 +18,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "about", "th": "เกี่ยวกับ" }, "description": module.exports.description, "description_localizations": { - "en-US": "See information about bots.", "th": "ดูข้อมูลเกี่ยวกับบอท" }, }, @@ -39,8 +37,8 @@ module.exports.function.command = { .setColor(clientColor) .setTimestamp(new Date(contentUpdate)) .setAuthor({ "name": clientUsername, "iconURL": clientAvatar, "url": "https://shiorus.web.app/" }) - .setFooter({ "text": interaction.client.translate.commands.about.update_on, "iconURL": "https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/120/microsoft/310/fountain-pen_1f58b-fe0f.png" }); + .setFooter({ "text": interaction.client.translate.commands.about.update_on }); - await interaction.editReply({ "embeds": [aboutEmbed] }); + await interaction.reply({ "embeds": [aboutEmbed] }); } }; \ No newline at end of file diff --git a/source/commands/me/bug.js b/source/commands/me/bug.js index 482f69db..6de005ef 100644 --- a/source/commands/me/bug.js +++ b/source/commands/me/bug.js @@ -9,7 +9,7 @@ module.exports = { "permissions": { "client": [PermissionsBitField.Flags.SendMessages] }, - "usage": "bug ", + "usage": "bug ", "function": { "command": {} } @@ -19,12 +19,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "bug", "th": "บัค" }, "description": module.exports.description, "description_localizations": { - "en-US": "Report error information about bots.", "th": "รายงานข้อผิดพลาดเกี่ยวกับบอท" }, "options": [ @@ -44,18 +42,17 @@ module.exports.function.command = { ] }, async execute(interaction) { - const inputMessage = interaction.options.get("message").value; + const inputMessage = interaction.options.getString("message"); - const db = getDatabase(); - const dbRef = ref(db, "projects/shioru/bugs"); + const bugsRef = ref(getDatabase(), "projects/shioru/bugs"); const authorUid = interaction.user.id; const authorTag = interaction.user.tag; const date = new Date(); - await interaction.editReply(interaction.client.translate.commands.bug.sending); + await interaction.reply(interaction.client.translate.commands.bug.sending); - await update(push(dbRef), { + await update(push(bugsRef), { "message": inputMessage, "user": authorTag, "uid": authorUid, diff --git a/source/commands/me/credits.js b/source/commands/me/credits.js index 46172ca6..3807002c 100644 --- a/source/commands/me/credits.js +++ b/source/commands/me/credits.js @@ -18,12 +18,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "credits", "th": "เครดิต" }, "description": module.exports.description, "description_localizations": { - "en-US": "Credit of other creators.", "th": "เครดิตของผู้สร้างรายอื่น" } }, @@ -38,7 +36,7 @@ module.exports.function.command = { .setDescription(interaction.client.translate.commands.credits.creator_credit_description) .setColor(clientColor) .setTimestamp(new Date(contentUpdate)) - .setFooter({ "text": interaction.client.translate.commands.credits.update_on, "iconURL": "https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/120/microsoft/209/lower-left-ballpoint-pen_1f58a.png" }) + .setFooter({ "text": interaction.client.translate.commands.credits.update_on }) .setAuthor({ "name": clientUsername, "iconURL": clientAvatar, "url": "https://shiorus.web.app/" }) .addFields( [ @@ -49,8 +47,6 @@ module.exports.function.command = { ] ); - await interaction.editReply({ - "embeds": [creditEmbed] - }); + await interaction.reply({ "embeds": [creditEmbed] }); } }; \ No newline at end of file diff --git a/source/commands/me/donate.js b/source/commands/me/donate.js index fb4b86ad..6536e5b5 100644 --- a/source/commands/me/donate.js +++ b/source/commands/me/donate.js @@ -21,20 +21,23 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "donate", "th": "บริจาค" }, "description": module.exports.description, "description_localizations": { - "en-US": "Donate to support bots and bot developers.", "th": "บริจาคเพื่อสนับสนุนบอทและนักพัฒนาบอท" } }, async execute(interaction) { + const github = "https://github.com/sponsors/Maseshi"; const patreon = "https://www.patreon.com/maseshi"; const bmc = "https://www.buymeacoffee.com/maseshi"; const row = new ActionRowBuilder() .addComponents( + new ButtonBuilder() + .setURL(github) + .setLabel('Github') + .setStyle(ButtonStyle.Link), new ButtonBuilder() .setURL(patreon) .setLabel('Patreon') @@ -45,7 +48,7 @@ module.exports.function.command = { .setStyle(ButtonStyle.Link) ); - await interaction.editReply({ + await interaction.reply({ "content": interaction.client.translate.commands.donate.thank_you_in_advance_message, "components": [row] }); diff --git a/source/commands/me/help.js b/source/commands/me/help.js index 2919d405..6a087308 100644 --- a/source/commands/me/help.js +++ b/source/commands/me/help.js @@ -1,5 +1,6 @@ const { EmbedBuilder, PermissionsBitField } = require("discord.js"); const { readdirSync } = require("node:fs"); +const { BitwisePermissionFlags } = require("../../utils/clientUtils"); module.exports = { "enable": true, @@ -9,22 +10,20 @@ module.exports = { "permissions": { "client": [PermissionsBitField.Flags.SendMessages] }, - "usage": "help (command: name, aliases)", - "function": { - "command": {} - } + "usage": "help [command(String)]", + "function": { + "command": {} + } }; module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "help", "th": "ช่วยด้วย" }, "description": module.exports.description, "description_localizations": { - "en-US": "Get help with the use of bots.", "th": "รับความช่วยเหลือเกี่ยวกับการใช้บอท" }, "options": [ @@ -43,54 +42,51 @@ module.exports.function.command = { ] }, async execute(interaction) { - let inputCommand = interaction.options.get("command"); + const inputCommand = interaction.options.getString("command") ?? ""; const info = new EmbedBuilder() .setColor("#E01055") .setTitle(interaction.client.translate.commands.help.document_name) + .setURL("https://shiorus.web.app/commands") .setAuthor({ "name": interaction.client.user.username, "iconURL": interaction.client.user.displayAvatarURL() }) .setFooter({ "text": interaction.client.translate.commands.help.request_by + " " + interaction.user.username, "iconURL": interaction.user.displayAvatarURL() }) .setTimestamp(); if (inputCommand) { - let commands; + const command = interaction.client.commands.get(inputCommand); - if (interaction.client.commands.has(inputCommand.value)) commands = interaction.client.commands.get(inputCommand.value); - if (interaction.client.aliases.has(inputCommand.value)) commands = interaction.client.commands.get(interaction.client.aliases.get(inputCommand.value)); - if (!commands) { + if (!command) { info.setTitle(interaction.client.translate.commands.help.command_incorrect) .setDescription(interaction.client.translate.commands.help.command_incorrect_guide) - return await interaction.editReply({ "embeds": [info] }); - } - - inputCommand = commands; + await interaction.reply({ "embeds": [info] }); + } else { + info.setTitle(interaction.client.translate.commands.help.command_detail + command.name.slice(0, 1).toUpperCase() + command.name.slice(1)) + .setDescription([ + interaction.client.translate.commands.help.commands_description[2], + "```", + interaction.client.translate.commands.help.command.replace("%s", (command.name.slice(0, 1).toUpperCase() + command.name.slice(1))), + interaction.client.translate.commands.help.description.replace("%s", (command.description ?? interaction.client.translate.commands.help.no_description)), + interaction.client.translate.commands.help.how_to_use.replace("%s", ("/" + (command.usage ?? interaction.client.translate.commands.help.unknown_how_to_use))), + interaction.client.translate.commands.help.category.replace("%s", (command.category ?? "General")), + interaction.client.translate.commands.help.user_permissions.replace("%s", (command.permissions.user ? command.permissions.user.map(permission => BitwisePermissionFlags[permission]).join(", ") : interaction.client.translate.commands.help.no_need_permissions)), + interaction.client.translate.commands.help.client_permissions.replace("%s", (command.permissions.client ? command.permissions.client.map(permission => BitwisePermissionFlags[permission]).join(", ") : interaction.client.translate.commands.help.no_need_permissions)), + "```" + ].join("\n")); - info.setTitle(interaction.client.translate.commands.help.command_detail + inputCommand.name.slice(0, 1).toUpperCase() + inputCommand.name.slice(1)) - .setDescription([ - "```" + interaction.client.translate.commands.help.command + (inputCommand.name.slice(0, 1).toUpperCase() + inputCommand.name.slice(1)), - interaction.client.translate.commands.help.description + (inputCommand.description || interaction.client.translate.commands.help.no_description), - interaction.client.translate.commands.help.how_to_use + "/" + (inputCommand.command.usage ? inputCommand.command.usage : interaction.client.translate.commands.help.unknown_how_to_use), - interaction.client.translate.commands.help.type + (inputCommand.category ? inputCommand.category : "General") - ].join("\n")); - - await interaction.editReply({ "embeds": [info] }); + await interaction.reply({ "embeds": [info] }); + } } else { const categories = readdirSync("./source/commands/"); - await info.setDescription([ - interaction.client.translate.commands.help.commands_description[0], - interaction.client.translate.commands.help.commands_description[1], - interaction.client.translate.commands.help.commands_description[2], - interaction.client.translate.commands.help.commands_description[3] - ].join("\n")); + info.setDescription(interaction.client.translate.commands.help.commands_description.join("\n")); categories.forEach((category) => { const dir = interaction.client.commands.filter(dirs => dirs.category.toLowerCase() === category.toLowerCase()); const categorize = category.slice(0, 1).toUpperCase() + category.slice(1); if (!dir.size) return; - if (category === "owner" && interaction.user.id !== interaction.client.config.owner) return; + if (category === "owner" && ((interaction.user.id !== interaction.client.config.team.owner) || (!interaction.client.config.team.developer.includes(interaction.user.id)))) return; if (category === "owner") return info.addFields({ "name": "🔒 " + categorize + " - (" + dir.size + ")", "value": dir.map(dirs => "`" + dirs.name + "`").join(", ") }); if (category === "developer") return info.addFields({ "name": "⌨ " + categorize + " - (" + dir.size + ")", "value": dir.map(dirs => "`" + dirs.name + "`").join(", ") }); if (category === "settings") return info.addFields({ "name": "⚙️ " + categorize + " - (" + dir.size + ")", "value": dir.map(dirs => "`" + dirs.name + "`").join(", ") }); @@ -103,7 +99,7 @@ module.exports.function.command = { ); }); - await interaction.editReply({ "embeds": [info] }); + await interaction.reply({ "embeds": [info] }); } } }; \ No newline at end of file diff --git a/source/commands/me/say.js b/source/commands/me/say.js index 6c6c7181..9c3e7e75 100644 --- a/source/commands/me/say.js +++ b/source/commands/me/say.js @@ -9,7 +9,7 @@ module.exports = { "user": [PermissionsBitField.Flags.ManageMessages], "client": [PermissionsBitField.Flags.SendMessages] }, - "usage": "say (channel: name, id) ", + "usage": "say [channel]", "function": { "command": {} } @@ -19,12 +19,10 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "say", "th": "พูด" }, "description": module.exports.description, "description_localizations": { - "en-US": "Let the bot print instead", "th": "ปล่อยให้บอทพิมพ์แทน" }, "options": [ @@ -63,23 +61,15 @@ module.exports.function.command = { ] }, async execute(interaction) { - const inputText = interaction.options.get("text").value; - const inputChannel = interaction.options.get("channel"); + const inputText = interaction.options.getString("text"); + const inputChannel = interaction.options.getChannel("channel") ?? ""; if (!inputChannel) { - await interaction.editReply(inputText); - await interaction.followUp({ - "content": interaction.client.translate.commands.say.success, - "ephemeral": true - }); + await interaction.channel.send(inputText); + await interaction.reply({ "content": interaction.client.translate.commands.say.success, "ephemeral": true}); } else { - const channel = interaction.guild.channels.cache.find(channels => (channels.id === inputChannel.value) || (channels.name === inputChannel.value)); - - await channel.send(inputText); - await interaction.editReply({ - "content": interaction.client.translate.commands.say.success, - "ephemeral": true - }); + await inputChannel.send(inputText); + await interaction.reply({ "content": interaction.client.translate.commands.say.success, "ephemeral": true}); } } } \ No newline at end of file diff --git a/source/commands/music/autoplay.js b/source/commands/music/autoplay.js index 5a3cd64d..63185fd7 100644 --- a/source/commands/music/autoplay.js +++ b/source/commands/music/autoplay.js @@ -18,23 +18,21 @@ module.exports.function.command = { "data": { "name": module.exports.name, "name_localizations": { - "en-US": "autoplay", "th": "เล่นอัตโนมัติ" }, "description": module.exports.description, "description_localizations": { - "en-US": "Turn on / off automatic music playing", "th": "เปิด/ปิดการเล่นเพลงอัตโนมัติ" } }, async execute(interaction) { const queue = interaction.client.music.getQueue(interaction); - if (!queue) return await interaction.editReply(interaction.client.translate.commands.autoplay.no_queue); - if (interaction.user.id !== queue.songs[0].user.id && queue.autoplay === false) return await interaction.editReply(interaction.client.translate.commands.autoplay.not_queue_owner); + if (!queue) return await interaction.reply(interaction.client.translate.commands.autoplay.no_queue); + if (interaction.user.id !== queue.songs[0].user.id && queue.autoplay === false) return await interaction.reply(interaction.client.translate.commands.autoplay.not_queue_owner); const mode = interaction.client.music.toggleAutoplay(interaction); - await interaction.editReply(mode ? interaction.client.translate.commands.autoplay.on : interaction.client.translate.commands.autoplay.off); + await interaction.reply(mode ? interaction.client.translate.commands.autoplay.on : interaction.client.translate.commands.autoplay.off); } }; \ No newline at end of file diff --git a/source/commands/music/filter.js b/source/commands/music/filter.js index 495c0acb..845cfc41 100644 --- a/source/commands/music/filter.js +++ b/source/commands/music/filter.js @@ -3,12 +3,12 @@ const { EmbedBuilder, PermissionsBitField } = require("discord.js"); module.exports = { "enable": true, "name": "filter", - "description": "Filter your music to be more powerful.", + "description": "Add more powerful filters to your music.", "category": "music", "permissions": { "client": [PermissionsBitField.Flags.SendMessages] }, - "usage": "filter