简体   繁体   中英

I need help creating a warning command in Discord.JS

I did this command to warn members and send a message in the DM, but I want the bot to tell the members in which server they were warned.

if (command === "warn") {
    let dUser = message.guild.member(message.mentions.users.first()) || message.guild.members.get(args[0]);
    if (!message.member.hasPermission("ADMINISTRATOR")) return message.reply("You can't use that command!")
    if (!dUser) return message.channel.send("Can't find user!")
    let dMessage = args.join(" ").slice(22);
    if (dMessage.length < 1) return message.reply('what is the reason???')

    dUser.send(`${dUser}, You have been warned for doing ${dMessage}`)

    message.channel.send(`${dUser} has been warned for doing ${dMessage} :thumbsdown:`)

Message has a property Guild , which is the guild in which the message was sent. You can just use message.guild.name to get the guild name.


if (command === "warn") {
    let dUser = message.guild.member(message.mentions.users.first()) || message.guild.members.get(args[0]);
    if (!message.member.hasPermission("ADMINISTRATOR")) return message.reply("You can't use that command!")
    if (!dUser) return message.channel.send("Can't find user!")
    let dMessage = args.join(" ").slice(22);
    if (dMessage.length < 1) return message.reply('what is the reason???')

    dUser.send(`${dUser}, You have been warned for doing ${dMessage} in the server ${message.guild.name}`)

    message.channel.send(`${dUser} has been warned for doing ${dMessage} :thumbsdown:`)

i recommend use a database to store the data which user get warn how many time. if the user has been warn let's say 3 times then perma ban the user

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM