User Tools

Site Tools



discordchat

This is an old revision of the document!


Discord Chat

This addon will send in-game chat to a discord channel. It will also take any messages (and commands) sent in that same discord channel and send it in-game.

As an example, imagine if someone talks to you on your linkshell 3. You can see the chat in Discord on your phone, and you can reply to them in the in-game linkshell with:

!l3 Hello.

Opening the Discord Chat Addon Window

The Discord Chat Plug-in window is under the FFXIVMinion menu.

Creating a Discord Server and Channel You will likely want a private server for this plug-in, for your own privacy.

- See How do I create a server? - Optionally, create a separate channel for your bot to use. - Get the channel ID of the channel you'd like to use. - In Discord, open your User Settings. Under Appearance, make sure Enable Developer Mode is checked on. - Right-click on the Discord text channel you would like to use, and press Copy ID. This will copy the channel ID to your clipboard. - Paste the ID into MMOMinion's Discord Chat plugin, under Bot Token/Channel, in Channel.

Creating a Bot and Receiving a Token

Create a bot starting here.

- Log in and click New Application. - Choose anything you want a name. Something like FF14 Chatbot is appropriate. - On the left side, under Settings, click on Bot. - Under Build-A-Bot, click on Add Bot. Hit Yes, do it! on the confirmation that pops up. - Optionally, configure your bot's username here. - Under Token, click Copy to copy the token to your clipboard. - Paste the bot token into the Discord Chat addon in MMOMinion, under Bot Token/Channel, in Token. - On the left side, go to OAuth2. Scroll down to Scopes and check bot. - Copy the URL under the checkboxes in Scopes and visit the URL in your clipboard. - Log-in to discord and authorize the bot to join your server. - Activate the bot token, in the next section.

Activating the Bot Token

Each bot token needs to be activated once it's created, before it can be used by the Discord Chat addon. This only needs to be done once.

Paste the token into the form below, then hit Activate.


Public API for Other Addons

Other plugins can send messages and listen for messages through a public API. With DiscordChat installed, you can call

discord_chat_api.Register(Plugin Name, Command Prefix, Command Callback)

and it will return you a function to send messages with.

Here's an example addon that sends and listens for commands.

-- Discord chat API example.
--
-- Look for a global discord_chat_api variable.
-- discord_chat_api.Register(Plugin Name, Command Prefix, Command Callback)
-- returns a function, SendMessage(message)
--
-- SendMessage will let you send a message through the bot
-- Command Callback is a single argument function that takes a message whenever
-- a discord message is sent with the prefix
--
-- Note that there is currently a ~5 second delay in receiving messages
-- and a ~2 second delay in sending
 
local test_discord_plugin = {}
test_discord_plugin.gui_open = true
test_discord_plugin.received = {}
 
function test_discord_plugin.ModuleInit()
    -- Menu item
    ml_gui.ui_mgr:AddMember({
        id = "FFXIVMINION##TEST_DISCORD_PLUGIN", name = "Test Discord Plugin",
        onClick = function()
            test_discord_plugin.gui_open = not test_discord_plugin.gui_open
        end},
        "FFXIVMINION##MENU_HEADER")
 
    -- Register with discord chat
    if discord_chat_api ~= nil then
        test_discord_plugin.SendMessage = discord_chat_api.Register(
            "test discord plugin", "test", test_discord_plugin.ProcessMessage)
    end
end
 
function test_discord_plugin.ProcessMessage(message)
    d("Received Message")
    d(message)
    table.insert(test_discord_plugin.received, message.content)
end
 
function test_discord_plugin.Draw(event, ticks)
    if test_discord_plugin.gui_open then
        GUI:SetNextWindowSize(100,50,GUI.SetCond_FirstUseEver)
        test_discord_plugin.visible, test_discord_plugin.gui_open = GUI:Begin(
            "Test Discord Chat",
            test_discord_plugin.gui_open)
        if test_discord_plugin.visible then
            local pushed = GUI:Button("Send Message")
            if pushed then
                test_discord_plugin.SendMessage("Test Message From Plugin")
            end
            for _, recv in pairs(test_discord_plugin.received) do
                GUI:Text(recv)
            end
        end
        GUI:End()
    end
end
 
RegisterEventHandler("Gameloop.Draw", test_discord_plugin.Draw,
    "Test Discord Plugin")
RegisterEventHandler("Module.Initalize", test_discord_plugin.ModuleInit)
discordchat.1554354675.txt.gz · Last modified: 2019/04/04 05:11 by mochi