Corey
DIAdiscord.js - Imagine an app
•Created by Corey on 3/2/2024 in #djs-questions
custom code for the bot
Or I can ask a friend for help If that's allowed.
8 replies
DIAdiscord.js - Imagine an app
•Created by Corey on 3/2/2024 in #djs-questions
custom code for the bot
Here's the code, not sure if it's right
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('message', message => {
if (!message.content.startsWith('/')) return; // Check if the message starts with '/'
const args = message.content.slice(1).trim().split(' ');
const command = args.shift().toLowerCase();
if (command === 'punish') {
// Check if the user has permission to use this command
if (!message.member.hasPermission('ADMINISTRATOR')) {
return message.reply('You do not have permission to use this command.');
}
// Parse arguments
const username = args[0];
const rank = args[1];
const punishment = args[2];
const reason = args.slice(3).join(' ');
const duration = args[4];
const note = args.slice(5).join(' ');
const approvedBy = message.author.username;
// Check if all required arguments are provided
if (!username || !rank || !punishment || !reason || !duration || !note || !approvedBy) {
return message.reply('Please provide all the required arguments: Username, Rank, Punishment, Reason, Duration, Note, Approved by.');
}
// Check if punishment is zero tolerance policy and if user mentioned
if (punishment.toLowerCase() === 'zero tolerance policy') {
const mentionedUser = message.mentions.users.first();
if (!mentionedUser) {
return message.reply('You need to mention the user when using zero tolerance policy.');
}
}
// Perform action based on the punishment
// Here you can add your logic to apply the punishment, like adding a role, sending a message, etc.
message.channel.send(`Punishment applied to ${username} for ${reason}. Approved by ${approvedBy}.`);
}
});
client.login('your-bot-token');
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('message', message => {
if (!message.content.startsWith('/')) return; // Check if the message starts with '/'
const args = message.content.slice(1).trim().split(' ');
const command = args.shift().toLowerCase();
if (command === 'punish') {
// Check if the user has permission to use this command
if (!message.member.hasPermission('ADMINISTRATOR')) {
return message.reply('You do not have permission to use this command.');
}
// Parse arguments
const username = args[0];
const rank = args[1];
const punishment = args[2];
const reason = args.slice(3).join(' ');
const duration = args[4];
const note = args.slice(5).join(' ');
const approvedBy = message.author.username;
// Check if all required arguments are provided
if (!username || !rank || !punishment || !reason || !duration || !note || !approvedBy) {
return message.reply('Please provide all the required arguments: Username, Rank, Punishment, Reason, Duration, Note, Approved by.');
}
// Check if punishment is zero tolerance policy and if user mentioned
if (punishment.toLowerCase() === 'zero tolerance policy') {
const mentionedUser = message.mentions.users.first();
if (!mentionedUser) {
return message.reply('You need to mention the user when using zero tolerance policy.');
}
}
// Perform action based on the punishment
// Here you can add your logic to apply the punishment, like adding a role, sending a message, etc.
message.channel.send(`Punishment applied to ${username} for ${reason}. Approved by ${approvedBy}.`);
}
});
client.login('your-bot-token');
8 replies