我如何让一个不和谐的机器人DM踢出来?

时间:2020-06-25 00:28:24

标签: node.js discord.js

我正在为不和谐的机器人开个玩笑功能,如果在kick命令中没有第二个参数,它将只踢某个成员,然后向他们发送邀请链接到服务器。

    if(!message.content.startsWith(PREFIX)) return;

    let args = message.content.substring(PREFIX.length).split(" ");

    switch(args[0]){
        case 'kick':

            const user = message.mentions.users.first()

            if(user){
                const member = message.mentions.members.first();

                if(member){
                    member.kick('Kicked because someone told me to').then(() =>{
                        message.channel.send(`The user ${user.tag} was kicked`);
                    }).catch(err =>{
                        message.channel.send('I was unable to kick that person')
                        console.log(err);
                    });

                    }else{
                        message.channel.send('The user mentioned was not in this hell hole')
                    }
                }else{
                    message.channel.send('Since no valid name was given, Imma just kick Cameron instead')
                    message.channel.send('*kick <@549777121476608000>')
                    message.author.send("message")
                    deletetimer = setTimeout(remove, 980)
                    function remove () {
                        message.channel.bulkDelete(2)
                    }
                }
            }
            
        }
)

1 个答案:

答案 0 :(得分:0)

而不是拥有

const user = message.mentions.users.first();
const member = message.mentions.members.first();

您可以使用:

const member = message.mentions.members.first();
const user = member.user;

message.author.send是指调用命令的人,您需要从ID中获取成员,然后发送消息

else {
    //message.guild.members.get if you are using v11
    const cameron = message.guild.members.cache.get("549777121476608000");
    message.channel.send('Since no valid name was given, Imma just kick Cameron instead');

    cameron.send("Here's the invite: ")
        //sincey you already have the variable might aswell use .kick instead of sending '*kick <@549777121476608000>'
        .then(() => cameron.kick("Reason"))
        .catch(console.error);

    deletetimer = setTimeout(remove, 980);

    function remove() {
        //since you aren't sending '*kick <@549777121476608000>' anymore its 1, not 2
        message.channel.bulkDelete(1)
    }
}