Каков правильный синтаксис для отправки уже определенной переменной в определенный канал разногласий - PullRequest
0 голосов
/ 02 июня 2019

Я изучаю lua и недавно приобрел доступ к API по ссылке , которая в любом случае меня немного смущает. Но главная проблема, с которой я сталкиваюсь, - это получение заранее определенного Послания на определенный канал разногласий.

Я попытался отправить его как собственный код для вставки, не используя переменную по умолчанию, и это не сработало. Я попытался использовать функцию Set: Message ('message here') рядом с функцией Set: Channel ('Channel here'), чтобы не преобладать. Например Message:SetMessage('SendOnlineMessage'): SetChannel('MyChan'),

SendOnlineMessage:SetChannel('MyChan'),``` ```
SetEmbed{( 
title = "Online";
fields = {
{name = "ONLINE_MESSAGE_TITLE"; value = body["ONLINE_MESSAGE_DESCRIPTION"]; inline = false};
}
)} 
END OF EXAMPLES 

The API does NOT provide any way to edit what is sent in the "Relay" channel which is the default channel for both server messages in game and the SendOnlineMessage variable. 

This first part is the config file I know it is missing the ending curly bracket thats because i did not need to copy the anti cheat logging functions as theyre working. The second part is the lang file where everything is defined
```lua
Discord.Config = {
    --[[

            REQUIRED CONFIGURATION

    ]]

    --[[
        EnabledModules

        Parts of the addon that you wan't to enable. Make sure to
        configure the parts enabled in their respective section below.
    ]]
    EnabledModules = {
        ['Relay'] = true,
        ['Join Rewards'] = true,
        ['Rank Sync'] = true,
    },

    --[[
        HibernateThink

        This'll automatically enable sv_hibernate_think to make all timers
        and http requests work. (Highly recommended to keep enabled)
    ]]
    HibernateThink = true,

    --[[
        Creating Discord application:
        Go to https://discordapp.com/developers/applications/me and
        click on "Create an application".

        Set the name (and icon) to anything you want. It's used for as title
        for Rich Presence, bot name and application name when requesting
        permissions to join your Discord or link account.

        Copy the Client ID and Client Secret to the fields below.
    ]]
    ClientID = 'removed',
    ClientSecret = 'removed',

    --[[
        Now navigate to the "OAuth2" tab on the left.
        Click the "Add Redirect" button and add the following URL into it:
        https://garrysmod.site/discord

        Now click the "Bot" tab on the left.
        Then click on the "Add Bot" button, then confirm it's creation.

        After the bot gets created, click on the "Click to reveal token"
        button and copy and paste the WHOLE token in to the field below.
        (You may also want to check off the "Public Bot" checkbox, if you
        don't want to allow other people to invite your bot to their Discord)
    ]]
    BotToken = 'removed',

    --[[
        Inviting your bot to your Discord:

        Copy the Client ID and replace the "INSERT_CLIENT_ID_HERE" part at
        the end of the following url:
        https://discordapp.com/oauth2/authorize?scope=bot&permissions=805308416&client_id=INSERT_CLIENT_ID_HERE

        Then open the link in your browser and select your Discord from the list.
        Then authorize the application and you're done!

        NOTE: The bot needs all permissions to work (unless you don't want to use
        rank sync, you can disable manage roles permission)
    ]]

    --[[
        GuildID

        Your discord server's guild ID.

        Enable dev mode in Discord Settings by navigating into the "Appearance" tab
        and check the Developer Mode tickbox. Then right click your server and
        select "Copy ID" and copy it to the field below.
    ]]
    GuildID = 'removed',

    --[[

            END OF REQUIRED CONFIGURATION

    ]]



    --[[

            Relay Configuration

    ]]

    Relay = {
        --[[
            Channels

            "Relay" will have all the relay messages, and
            "Admin" will have all logging messages (ULX, SG, etc.)

            Either channel id or channel name (without #) are valid arguments.
            If the bot will be in multiple servers, use ID or unique channel names
            to avoid them conflicting.

            If you want to get the channel id:
            Enable dev mode in Discord Settings by navigating into
            the "Appearance" tab and check the Developer Mode tickbox.
            Then right click your channel and select "Copy ID".

            DEVELOPER:
            You can add additional channels here with name => channel id/name
            so that you can use them in your code and as argument for Message:SetChannel.
            Refer to Developer API on script page for additional info.
        ]]
        Channels = {
            Relay = '582253368777637898',
            Admin = '582240219747581955',
            MyChan = '584182548431634531',
        },

        --[[
            Exiles message dont touch!
        ]]



        --[[
            BotPrefix

            Prefix for all bot commands (e.g: !help)
        ]]
        BotPrefix = '!',

        --[[
            BotStatus

            Displayed as the bot's status. Max 32 characters.
        ]]
        BotStatus = 'status',

        --[[
            NamePrefix

            Prefix all players names with certain string (e.g: [GMOD])
        ]]
        NamePrefix = '[GMOD]',

        --[[
            RelayChat

            Should chat messages get relayed into Discord?
        ]]
        RelayChat = true,

        --[[
            RelayJoinLeave

            Should join/leave messages get relayed into Discord?
        ]]
        RelayJoinLeave = false,

        --[[
            Mentioning

            Allow mentioning of Discord users from Gmod -> Discord
        ]]
        Mentioning = true,

        --[[
            TeamChatEnabled

            Should team chat be relayed into Discord?
        ]]
        TeamChatEnabled = false,

        --[[
            SendOnlineMessage

            Should "Server is now online!" type of message be sent on server bootup?
            NOTE: Translatable in discord_lang.lua
        ]]
        SendOnlineMessage = true,


Часть 2:

Discord.Lang = {
    --[[

        Start of Lang configuration

    ]]


    --[[
        Extra supported strings for ANY language string:
        <server_ip> -> Server's IP
        <join_url> -> steam://connect/<server_ip>
        <hostname> -> Server's Hostname
        <map> -> Server's Map
        <gamemode> -> Server's Gamemode
    ]]

    --[[
        Online Message
    ]]
    ONLINE_MESSAGE_TITLE = '<hostname> is now online!',
    ONLINE_MESSAGE_DESCRIPTION = 'Join at steam://connect/MYIPREMOVEDFORPRIVACY! \n Direct connect: <server_ip> \n Gamemode: <gamemode>',
}
...