Attempt to call field 'contains' (a nil value) | How can I check the table to see if it has a server?

纵然是瞬间 提交于 2019-12-25 09:02:13

问题


What I am trying (Discord Bot) is to make a command called !say serverID channelID arg

The point of this command is that I will pm the bot with this command and the bot writes the arg in the defined channelID from the server.

Library (litcord): https://github.com/satom99/litcord

A part of the code (Yes, this has issues...):

        local server = client.servers:getAll('id', serverID)
        if server then 
            if server.contains('id', serverID) then
                for _, serverID in pairs(server) do
                    if serverID == serverID then
                    return true
                    end
                    return false
                end
            end
        print(serverID, channelID, arg)
        return end

The full code:

client:on(
    'message',
    function(message)
    local userID = message.author.id
    local cmd, serverID, channelID, arg = string.match(message.content, '(%S+) (%d+) (%d+) (%S+.*)')
    local cmd = cmd or message.content
        if (cmd == "!say") and message.parent.is_private then 
            if (userID == "187590758360940545") then
            local server = client.servers:getAll('id', serverID)
            if server then 
                if server.contains('id', serverID) then
                    for _, serverID in pairs(server) do
                        if serverID == serverID then
                        return true
                        end
                        return false
                    end
                end
            print(serverID, channelID, arg)
            return end
            local channel = server.channels:get('id', channelID)

            client.channel = channelID
            message.channel:sendMessage(arg)
            else
            message:reply(":sob: Stop!!!!")
            return end
        end
    end
)

Things I am trying to:

Check the table to see if it has a server

and the same for channel

etc....

来源:https://stackoverflow.com/questions/38530639/attempt-to-call-field-contains-a-nil-value-how-can-i-check-the-table-to-se

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!