custom code for the bot

Hello, I'm go be creating a bot soon, I have a question, so I'm using ChatGPT to help me with custom code, but what version should I use?
7 Replies
d.js toolkit
d.js toolkit•9mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Corey
CoreyOP•9mo ago
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');
-Carlos👑
-Carlos👑•9mo ago
you should always try to use the latest version, and do not use ChatGPT since it's very outdated
-Carlos👑
-Carlos👑•9mo ago
instead, learn js and follow the official guide https://discordjs.guide/#introduction #resources
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Corey
CoreyOP•9mo ago
Or I can ask a friend for help If that's allowed.
-Carlos👑
-Carlos👑•9mo ago
sure i guess
Spaxter
Spaxter•9mo ago
Just remember that when asking for help people will assume you know basic JavaScript. If you don't, you'll most likely not understand the answers you're given and they'll tell you the same thing. Making a Discord bot is not a beginner friendly project.
Want results from more Discord servers?
Add your server