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

时间:2021-06-12 01:20:25

标签: javascript discord 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)
        });
        
    }

在这种情况下,管理员会写一条消息(它正确地作为参数出现),而我已经走到了这一步,我只想在我的控制台中返回反应用户。我几乎被困在这里。

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

1 个答案:

答案 0 :(得分:0)

此代码缺少 },您应该尝试使用 async/await,这对于新手来说更易于查看和理解。作为您在 filter 上使用的 createReactionCollector 代码,您捕获的表情符号由发送机器人命令请求的人做出反应,而不是每个用户 (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');
            }
        });
        
    }