繁体   English   中英

您如何向对机器人发送的消息做出反应的用户发送 DM? (不和谐.JS)

[英]How do you send a DM to users that react to a bot sent message? (Discord.JS)

几乎如标题所说,但我只是想弄清楚如何让我的机器人向任何对其发送的消息做出反应的人发送 DM。

    name: "sign-up",
    description: "signup thing",
    category: "misc",
    execute(message, client){

        const args = message.content.slice(prefix.length).trim().split(' ');
        const command = args.shift().toLowerCase();
        const say = args.join(" ");


        if (!args.length) {
            return message.channel.send(`You didn't provide any arguments, ${message.author}!`);
        }

        message.channel.send(say).then(message =>{
            message.react("✅")

        const filter = (reaction, user) => {
            return ['✅'].includes(reaction.emoji.name) && user.id === message.author.id;
        };
        
        const collector = message.createReactionCollector(filter, {time: 60000 });
        collector.on('collect', (reaction, reactionCollector) => {
            reaction.users.last().send('Some')
            .catch(console.error)
        });
        
    }

在这种情况下,管理员将编写一条消息(正确显示为 args),而我已经走到了这一步,我只想在控制台中返回反应用户。 我几乎被困在这里。

如果代码很奇怪,请道歉。

此代码丢失} ,您应该尝试使用async/await ,这对于新手来说更容易查看和理解。 作为您在createReactionCollector上使用的filter代码,您将捕获由发送机器人命令请求的人做出反应的表情符号,而不是每个用户( user.id === message.author.id

    name: "sign-up",
    description: "signup thing",
    category: "misc",
    async execute(message, client){

        const args = message.content.slice(prefix.length).trim().split(' ');
        const command = args.shift().toLowerCase();
        const say = args.join(" ");


        if (!args.length) {
            return message.channel.send(`You didn't provide any arguments, ${message.author}!`);
        }

        const newMsg = await message.channel.send(say)
        newMsg.react("✅")   
        const filter = (reaction, user) => {
            return user.id === message.author.id;
        };
        const collector = message.createReactionCollector(filter, {time: 60000 });
        collector.on('collect', (reaction, user) => {
            if (r.emoji.name === '✅') {
               user.send('Some');
            }
        });
        
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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