-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81d704f
commit dc97564
Showing
7 changed files
with
123 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { Events } = require("discord.js"); | ||
const listCommands = require("../utils/loadCommands").listCommands; | ||
|
||
module.exports.run = async (client) => { | ||
client.on(Events.InteractionCreate, (interaction) => { | ||
if (interaction.isChatInputCommand()) { | ||
try { | ||
listCommands[interaction.commandName](interaction); | ||
} catch (error) { | ||
interaction.reply("There is an error with the command"); | ||
} | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const { ApplicationCommandOptionType } = require("discord.js"); | ||
const updateUser = require("../../utils/updateUser").updateUser; | ||
|
||
const listOfTimezones = [ | ||
"Pacific/Kiritimati", | ||
"Pacific/Tongatapu", | ||
"Pacific/Apia", | ||
"Asia/Anadyr", | ||
"Asia/Kamchatka", | ||
"Asia/Tokyo", | ||
"Asia/Hong_Kong", | ||
"Asia/Kolkata", | ||
"Asia/Dubai", | ||
"Europe/Moscow", | ||
"Europe/Paris", | ||
"Europe/London", | ||
"Africa/Cairo", | ||
"Africa/Nairobi", | ||
"Asia/Kuwait", | ||
"Europe/Athens", | ||
"Asia/Baghdad", | ||
"Europe/Istanbul", | ||
"Asia/Tehran", | ||
"Asia/Kabul", | ||
"Asia/Baku", | ||
"Asia/Ashgabat", | ||
"Asia/Muscat", | ||
"Asia/Tashkent", | ||
"Asia/Almaty", | ||
]; | ||
|
||
const choices = []; | ||
for (const timezone of listOfTimezones) { | ||
choices.push({ name: timezone, value: timezone }); | ||
} | ||
|
||
module.exports = { | ||
data: { | ||
name: "settimezone", | ||
description: "Set the time zone, to get the time right", | ||
options: [ | ||
{ | ||
type: ApplicationCommandOptionType.String, | ||
name: "timezone", | ||
description: "Value for the new time zone", | ||
required: true, | ||
choices, | ||
}, | ||
], | ||
}, | ||
async execute(interaction) { | ||
await interaction.deferReply({ ephemeral: true }); | ||
const timeZone = interaction.options.get("timezone").value; | ||
const userName = interaction.user.userName; | ||
const userId = interaction.user.id; | ||
|
||
const result = await updateUser({ userName: userName, userId: userId, data: { timeZone } }); | ||
return interaction.followUp( | ||
result ? "Time zone has been updated" : "ERROR: Could not update time zone. Try again later." | ||
); | ||
}, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const { REST, Routes } = require("discord.js"); | ||
const fs = require("fs"); | ||
require("dotenv").config(); | ||
|
||
const GUILD_ID = process.env.GUILD_ID; | ||
const TOKEN = process.env.DISCORD_TOKEN; | ||
|
||
const listCommands = {}; | ||
module.exports.listCommands = listCommands; | ||
|
||
module.exports.run = async (client) => { | ||
// Create all commands | ||
const commands = []; | ||
const commandFolders = fs.readdirSync(__dirname + "/../interactions/commands/"); | ||
|
||
for (const folder of commandFolders) { | ||
// Grab all the command files from the commands directory you created earlier | ||
const commandsPath = __dirname + "/../interactions/commands/" + folder; | ||
|
||
const command = require(commandsPath); | ||
if ("data" in command && "execute" in command) { | ||
const data = command.data; | ||
listCommands[data.name] = command.execute; | ||
commands.push(data); | ||
} else { | ||
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`); | ||
} | ||
} | ||
|
||
// Construct and prepare an instance of the REST module | ||
const rest = new REST().setToken(TOKEN); | ||
|
||
// and deploy your commands! | ||
try { | ||
client.application.commands.set(commands, GUILD_ID); | ||
} catch (error) { | ||
// And of course, make sure you catch and log any errors! | ||
console.error(error); | ||
} | ||
}; |