如何停止在lua discord bot中重复发送相同的消息?

时间:2020-11-02 10:12:58

标签: lua discord

我有一个机器人,可以从dcs服务器将事件发送到我的不和谐事件。问题在于,当目标被枪击中时,它会为每个子弹重复相同的事件。如何停止重复发送同一封邮件?

  local function hit(event)
        if event.id == world.event.S_EVENT_HIT then
            log:info(event)
            if Unit.getName(event.initiator) then
                log:info(Unit.getName(event.initiator))
                local newU = mist.utils.deepCopy(mist.DBs.unitsByName[Unit.getName(event.initiator)])
                newU.playerName = Unit.getName(event.initiator)
                mist.DBs.activeHumans[Unit.getName(event.initiator)] = newU
                local targetU = Unit.getName(event.target)
                local weaponU = Weapon.getTypeName(event.weapon)
                local uname = Unit.getPlayerName(event.initiator) 
               if targetU == nil then
                --targetU = Unit.getName(event.target)
                --else 
                --if targetU == nil then
                targetU = Unit.getPlayerName(event.target)
                --return
                --else
               -- targetU = 'Unknown target'
                --end
                end
                if weaponU == nil then
                weaponU = 'Unknown weapon'
                end 
                if uname == nil then
               uname = Unit.getName(event.initiator)
                else
                uname = 'Unknown'
                end 
                
                HypeMan.sendBotMessage ( '```css\n'..'[' .. weaponU .. " with " .. targetU .. " hit " .. uname..']'..'\n```' )
                
            end
         
            
        end
    end

mist.addEventHandler(hit)

0 个答案:

没有答案