【问题标题】:Is there an way to call an client.on?有没有办法调用client.on?
【发布时间】:2019-11-17 11:06:53
【问题描述】:

我想做一个反应游戏,它需要函数消息、反应和用户,有没有办法我可以从另一个调用另一个 client.on(在我的情况下是 bot.on)函数? (代码中不相关的部分缺失)

first client.on

second client.on

subfunction

bot.on('message', function (message) {
    if (message.content.startsWith(prefix)) {
        var fetchedMessages = message.channel.fetchMessages({ limit: 99 });
        var args = message.content.substring(1).split(' ');
        var cmd = args[0];
        args = args.splice(1);
        switch (cmd) {
            case 'react':
                messageReactionAdd()
                break;

---------------------------------------------------------------------------

bot.on('messageReactionAdd', (message,reaction, user) => {
    minigames.reaction(message,user,reaction)
});

---------------------------------------------------------------------------

module.exports = {
    reaction: function (reaction,message) {
        var reacted =
        message.channel.send("Auf die Plätze").then(function(message){
            setTimeout(function () {message.edit("Fertig ?")  }, 5000)
            setTimeout(function () {message.edit("LOS!")  }, 10000)
            setTimeout(function () {message.react("????")  }, 10000)
            setTimeout(function () {message.edit("STOP ")  }, 17000)
            setTimeout(function () {  }, 1000)
        })
        if(reaction.emoji.name === "????") {
            console.log(reaction.users);
        }
    },

【问题讨论】:

    标签: node.js discord discord.js


    【解决方案1】:

    Discord.js Client 实际上是 EventEmitter 实例。 emitter.on() 附加了一个监听器,当定义的事件发出时将被调用。要首先发出事件,请使用emitter.emit() 方法,就像这样...

    emitter.emit('event', ...parameters);
    

    例如...

    bot.emit('messageReactionAdd', reaction, user);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-24
      • 1970-01-01
      • 2021-03-28
      • 2012-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-13
      相关资源
      最近更新 更多