Ad
How To Add "reason" Thing To Ban Command
I am programming a discord bot in node.js (not master) and I an working on a kick and ban command. I'm trying to make the BOT write the ban log of the user. like +ban @user reason. I did +ban @user but i can't make reason thing.
if (!message.member.hasPermission("BAN_MEMBERS")) return;
if (message.content.startsWith('+ban')) {
const user = message.mentions.users.first();
if (user) {
const member = message.guild.member(user);
if (member) {
member.ban({
reason: 'reason',
}).then(() => {
message.channel.send(`${user.tag} BAN!`);
}).catch(err => {
message.channel.send('Bu çar çok güçlü, banlayamıyorum! ');
console.error(err);
});
} else {
message.channel.send('Kullanıcı sunucuda değil.');
}
} else {
message.channel.send('Adını ver banlayayım, sahip.');
}
}
});```
Ad
Answer
Simply use member.ban('reason here')
. Use an object if you need to delete previous messages and supply a reason, like so:
member.ban({days: 2, reason: 'bad'});
Now, just use this setup with the user's reason. Use a variable for the reason as a sliced version of the arguments array, joined with spaces.
Edit: Showing context...
if (message.content.toLowerCase().startsWith('+ban')) { // changed to case insensitive command
const member = message.mentions.members.first(); // keep in mind it isn't the best practice to use message.mentions to retrieve an argument
if (!member) return message.channel.send('no member mentioned');
let reason = args.slice(2).join(' '); // arguments should already be defined
member.ban(reason)
.then(message.channel.send('success'))
.catch(err => {
message.channel.send('something went wrong');
console.error();
});
}
Ad
source: stackoverflow.com
Related Questions
- → Maximum call stack exceeded when instantiating class inside of a module
- → Browserify api: how to pass advanced option to script
- → Node.js Passing object from server.js to external modules?
- → gulp-rename makes copies, but does not replace
- → requiring RX.js in node.js
- → Remove an ObjectId from an array of objectId
- → Can not connect to Redis
- → React: How to publish page on server using React-starter-kit
- → Express - better pattern for passing data between middleware functions
- → Can't get plotly + node.js to stream data coming through POST requests
- → IsGenerator implementation
- → Async/Await not waiting
- → (Socket.io on nodejs) Updating div with mysql data stops without showing error
Ad