added mognodb database
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// exampleCommand.js
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
const { connectToDatabase } = require('../../db.js');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('example')
|
||||
.setDescription('An example DB usage')
|
||||
.addStringOption(option =>
|
||||
option
|
||||
.setName('message')
|
||||
.setDescription('string to store')
|
||||
.setRequired(true)),
|
||||
async execute(interaction) {
|
||||
const dbClient = await connectToDatabase();
|
||||
const message = interaction.options.getString('message');
|
||||
|
||||
// Choose a DB + Collection
|
||||
const db = dbClient.db('discord');
|
||||
const collection = db.collection('test');
|
||||
|
||||
// Example: Insert something
|
||||
await collection.insertOne({ userId: interaction.user.id, message: message });
|
||||
|
||||
await interaction.reply('Successfully inserted your data into MongoDB.');
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
const { SlashCommandBuilder } = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("mute")
|
||||
.setDescription("mute misbehaving people")
|
||||
.addUserOption(option =>
|
||||
option
|
||||
.setName('target')
|
||||
.setDescription('The member to mute')
|
||||
.setRequired(true))
|
||||
.addIntegerOption(option =>
|
||||
option
|
||||
.setName('duration')
|
||||
.setDescription('The duration of the Mute (Minutes)')
|
||||
.setRequired(true))
|
||||
.addStringOption(option =>
|
||||
option
|
||||
.setName('reason')
|
||||
.setDescription('The reason of the mute')),
|
||||
async execute(interaction) {
|
||||
// Get the user and duration from the command options
|
||||
const target = interaction.options.getUser('target');
|
||||
const duration = interaction.options.getInteger('duration');
|
||||
|
||||
// Convert duration to milliseconds
|
||||
const durationMs = duration * 60 * 1000;
|
||||
|
||||
try {
|
||||
// Apply the timeout
|
||||
await target.timeout(durationMs);
|
||||
|
||||
await interaction.reply({
|
||||
content: `${target.tag} has been muted for ${duration} minutes.`
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
await interaction.reply({
|
||||
content: 'I was unable to mute the member.',
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
const quiz = require('./quiz.json');
|
||||
const {SlashCommandBuilder} = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("quiz")
|
||||
.setDescription("Start a cool quiz"),
|
||||
async execute(interaction) {
|
||||
const item = quiz[Math.floor(Math.random() * quiz.length)];
|
||||
await interaction.reply({
|
||||
content: `**Quiz Time!**\n${item.question}\n\n_You have 30 seconds to answer!_`,
|
||||
});
|
||||
|
||||
// Define a filter to check the correct answer
|
||||
const collectorFilter = (response) => {
|
||||
return (
|
||||
response.author.id === interaction.user.id && // Ensure it's the same user
|
||||
item.answers.some(
|
||||
(answer) => answer.toLowerCase() === response.content.toLowerCase()
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
try {
|
||||
// Await messages in the same channel
|
||||
const collected = await interaction.channel.awaitMessages({
|
||||
filter: collectorFilter,
|
||||
max: 1,
|
||||
time: 30000, // 30 seconds
|
||||
errors: ['time'],
|
||||
});
|
||||
|
||||
// If a message is collected, reply with the correct response
|
||||
const correctAnswer = collected.first();
|
||||
await interaction.followUp(
|
||||
`${correctAnswer.author} got the correct answer: **${correctAnswer.content}**! 🎉`
|
||||
);
|
||||
} catch (err) {
|
||||
// If no one answers in time
|
||||
await interaction.followUp(
|
||||
`⏳ Time's up! Nobody got the correct answer. The correct answers were: **${item.answers.join(', ')}**.`
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
[
|
||||
{
|
||||
"question": "What color is the sky?",
|
||||
"answers": ["blue"]
|
||||
},
|
||||
{
|
||||
"question": "How many letters are there in the alphabet?",
|
||||
"answers": ["26", "twenty-six", "twenty six", "twentysix"]
|
||||
}
|
||||
]
|
||||
@@ -1,13 +1,19 @@
|
||||
const {SlashCommandBuilder} = require("discord.js");
|
||||
const {SlashCommandBuilder, EmbedBuilder} = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("about")
|
||||
.setDescription("Information about this bot"),
|
||||
.setDescription("Information about this bot and creator"),
|
||||
async execute(interaction) {
|
||||
const exampleEmbed = new EmbedBuilder()
|
||||
.setColor(0x0099FF)
|
||||
.setTitle('About Page')
|
||||
.setDescription('I build this bot for managing my servers. (to lazy to write mor text rn)')
|
||||
.setImage('https://i.postimg.cc/QdZZwKVD/Screenshot-2024-12-25-005933.png')
|
||||
.setTimestamp();
|
||||
|
||||
await interaction.reply({
|
||||
content: "This bot has some general commands for moderation, but includes on or two unqiue features, like the currenc system. It's a small project to enhanced the programming skills of the creator.",
|
||||
ephemeral: true
|
||||
embeds: [exampleEmbed]
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user