gpt4 book ai didi

javascript - 如何让我的机器人等待提到的用户 discord.js 的回复?

转载 作者:行者123 更新时间:2023-12-04 08:15:36 24 4
gpt4 key购买 nike

我希望我的机器人只等待命令中提到的用户的聊天响应。
这是它应该如何工作:

  • 我发&tictactoe @someuser#1234
  • 机器人回复:
  • nathen418 wants to play a game of Tic-Tac-Toe with you. Do you accept?
    Yes or No
  • @someuser#1234 类型 YesNo
  • 机器人以 They want to play Tic-Tac-Toe with you! 之一响应或 They did not want to play with you. :(

  • 如果我@提及我自己( @nathen418#0002 ),这将正常工作。但是如果我发送命令 &tictactoe @someuser#1234@someuser#1234试图响应,机器人忽略它们。我希望机器人只监听 YesNo来自我提到的用户
    这是我的代码:
    const exceptionHandler = require('../handlers/exceptionHandler');
    const logToConsole = require('../events/logToConsole');
    const Discord = require('discord.js');

    module.exports = {
    tictactoeCMD: function (message, bot) {
    const member = message.mentions.members.first().id;
    message.channel.send(message.author.username + " wants to play a game of Tic-Tac-Toe with you. Do you accept?\n `Yes` or `No`")
    console.log(message.author.id)
    const collector = new Discord.MessageCollector(message.channel, m => m.author.id === message.author.id, { time: 10000 });
    collector.on('collect', message => {

    console.log(message.author.id)
    console.log("^ message author Below member id")
    console.log(member)
    if (message.author.id === member && message.content.toUpperCase() == "YES") {
    message.reply(" they want to play Tic-Tac-Toe with you!");
    } else if (message.author.id === member && message.content.toUpperCase() == "NO") {
    message.reply( " They did not want to play with you. :(");
    }
    })
    //logToConsole.command(message.guild, message);
    }
    }
    这是我运行机器人时发生的情况:
    Output of my code running
    完整代码可在 alpha 上获得github分支: https://github.com/Antares-Network/AntaresBot/tree/alpha

    最佳答案

    您目前正在做的是请求来自 的输入。留言作者 .
    看到您对获取提到的成员的输入感兴趣,您需要将收集到的消息作者的 ID 与您定义为 member 的成员 ID 进行比较。早些时候。
    最终代码:

    onst exceptionHandler = require('../handlers/exceptionHandler');
    const logToConsole = require('../events/logToConsole');

    const Discord = require('discord.js');

    module.exports = {
    tictactoeCMD: function (message, bot) {
    const member = message.mentions.members.first().id;
    message.channel.send(message.author.username + " wants to play a game of Tic-Tac-Toe with you. Do you accept?\n `Yes` or `No`")
    console.log(message.author.id)
    const collector = new Discord.MessageCollector(message.channel, m => m.author.id === member, { time: 10000 }); // <--- Line edited
    collector.on('collect', message => {
    console.log(message.author.id)
    console.log("^ message author Below member id")
    console.log(member)
    if (message.author.id === member && message.content.toUpperCase() == "YES") {
    message.reply(" they want to play Tic-Tac-Toe with you!");
    } else if (message.author.id === member && message.content.toUpperCase() == "NO") {
    message.reply( " They did not want to play with you. :(");
    }
    })
    //logToConsole.command(message.guild, message);
    }
    }

    关于javascript - 如何让我的机器人等待提到的用户 discord.js 的回复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65723157/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com