【问题标题】:How do you send a DM to users that react to a bot sent message? (Discord.JS)您如何向对机器人发送的消息做出反应的用户发送 DM? (不和谐.JS)
【发布时间】:2021-08-28 20:41:36
【问题描述】:

几乎是标题所说的,但我只是想弄清楚如何让我的机器人向对其发送的消息做出反应的任何人和每个人发送 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),而我已经走到了这一步,我只想在我的控制台中返回反应用户。我几乎被困在这里了。

抱歉,如果代码很奇怪。

【问题讨论】:

    标签: javascript discord discord.js


    【解决方案1】:

    此代码缺少},您应该尝试使用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');
                }
            });
            
        }
    

    【讨论】:

    • 这样的帮助,谢谢,但它并没有完全解决问题,我最终自己解决了。
    猜你喜欢
    • 2020-06-13
    • 2021-05-08
    • 2021-10-31
    • 1970-01-01
    • 2020-11-12
    • 2021-04-02
    • 2022-01-08
    • 2020-09-13
    • 2021-04-11
    相关资源
    最近更新 更多