【问题标题】:How would I make a discord bot DM someone that it just kicked?我如何让一个不和谐的机器人 DM 成为它刚刚踢的人?
【发布时间】:2020-06-25 09:28:11
【问题描述】:

我正在为一个不和谐机器人制作一个笑话功能,如果 kick 命令没有第二个参数,它只会踢某个成员,然后 DM 他们一个到服务器的邀请链接。

 if(!message.content.startsWith(PREFIX)) 返回;

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

    开关(参数 [0]){
        案例“踢”:

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

            如果(用户){
                常量成员 = message.mentions.members.first();

                如果(成员){
                    member.kick('被踢是因为有人告诉我').then(() =>{
                        message.channel.send(`用户${user.tag}被踢`);
                    }).catch(错误 =>{
                        message.channel.send('我无法踢那个人')
                        控制台日志(错误);
                    });

                    }别的{
                        message.channel.send('提到的用户不在这个地狱洞里')
                    }
                }别的{
                    message.channel.send('由于没有给出有效的名字,Imma 只是踢了 Cameron')
                    message.channel.send('*踢 ')
                    message.author.send("消息")
                    deletetimer = setTimeout(删除,980)
                    功能删除(){
                        message.channel.bulkDelete(2)
                    }
                }
            }
            
        }
)

【问题讨论】:

  • 请在 Stack Overflow 上使用适合工作场所的语言,而不是可能冒犯某些人或群体的语言。请参阅:Are expletives (cursing, swear words or vulgar language) allowed on SE sites?。请记住,使用攻击性语言往往会导致人们对您的帖子反应不佳(即他们可能会投反对票)。此外,您真的希望未来的雇主看到您在本应是专业的情况下使用这种语言吗?

标签: node.js discord.js


【解决方案1】:

而不是拥有

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)
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-23
    • 2019-02-22
    • 2020-01-29
    • 1970-01-01
    • 1970-01-01
    • 2018-07-21
    • 2020-04-29
    • 2020-04-15
    相关资源
    最近更新 更多