Oxide.Ext.Discord is an Oxide extension which acts as a bridge between Oxide and the Discord API.
Should you encounter a problem or bug with the extension, please feel free to create an issue here. Try to include as much detail as possible, including steps to reproduce the issue. A code example is highly appreciated.
To install the extension to your Oxide server, you must follow a few simple steps: 1) Shutdown the server. 2) Open the server files, and navigate to the "Managed" folder (eg. "RustDedicated/Managed") 3) Download the latest release. 4) Unzip the release. 5) Copy the "Oxide.Ext.Discord.dll" file into your "Managed" folder. 6) Start your server!
An API key is used to authenticate requests made to and from Discord.
Note: DO NOT SHARE YOUR API KEY! Sharing your key may result in punishments from Discord (including a platform-wide ban) if the token is used to abuse the API.
Obtaining an API Key: 1) Visit the official Discord Developers page here: Discord Developer Documenation 2) Click "New App". 3) Name your app and click create! Note: A description isn't required. 4) You will now be redirected to your created app, at the point you will need to click "Create a Bot User". 5) Under the newly created bot section, under "Username" you will see "Token". Reveal the token and copy it into your plugin. 6) Now it's time to add your new bot to your guild! To add your bot to your guild you must visit the following link, and replace "botUserID" with the client ID found at the top of your Discord app settings page: https://discordapp.com/oauth2/authorize?client_id=botUserID&scope=bot&permissions=8
Note: "permissions=8" in the link will provide the bot with administrative permissions so you won't have to give it some.
The following plugin is a simple example on how to use the extension. This plugin simply adds a 'sad' reaction to any message posted on the Discord server, and then broadcasts the message to the server chat.
using Oxide.Ext.Discord;
using Oxide.Ext.Discord.Attributes;
using Oxide.Ext.Discord.DiscordObjects;
namespace Oxide.Plugins
{
[Info("Discord Ext Example", "Your Name", "1.0.0")]
class DiscordExtExample : CovalencePlugin
{
// Define the DiscordClient field that will be set
// to when our DiscordClient is created & connected
[DiscordClient] DiscordClient Client;
void OnServerInitialized()
{
Discord.CreateClient(this, "<api key here>"); // Create a new DiscordClient
}
// Called when the connection is completed
void Discord_Ready(Ready ready)
{
Puts("Discord connected!");
// When this hook is called, our Client variable
// will be set to the main DiscordClient that
// has been created for us
Puts($"Connected to server: {Client.DiscordServer.name}");
}
// Called when a message is created on the Discord server
void Discord_MessageCreate(Message message)
{
// Add a sad reaction to the message
message.CreateReaction(Client, ":sad:");
// Post the message to chat
server.Broadcast($"Discord Message: {message.author.username} - {message.content}");
}
}
}
void DiscordSocket_Initalized(DiscordClient client)
{
Puts("Client Initalized!");
}
void DiscordSocket_HeartbeatSent()
{
Puts("Heartbeat sent to discord!");
}
void DiscordSocket_WebSocketOpened()
{
Puts("WebSocket Opened!");
}
void DiscordSocket_WebSocketClosed(string reason, int code, bool clean)
{
Puts("WebSocket closed!");
}
void DiscordSocket_WebSocketErrored(Exception exception, string message)
{
Puts($"WebSocket errored:.");
}
void Discord_Ready(Ready ready)
{
Puts("Discord is ready!");
}
void Discord_Resumed(Resumed resumed)
{
Puts("Discord Connection Resumed!");
}
void Discord_ChannelCreated(Channel channel)
{
Puts("Discord Channel Created");
}
void Discord_ChannelUpdate(Channel updatedChannel, Channel oldChannel)
{
Puts("Discord Channel Updated");
}
void Discord_ChannelDelete(Channel channel)
{
Puts("Discord Channel Deleted!");
}
void Discord_ChannelPinsUpdate(ChannelPinsUpdate update)
{
Puts("The pins on a channel have been updated!");
}
void Discord_GuildCreate(Guild guild)
{
Puts("A guild has been created!");
}
void Discord_GuildUpdate(Guild guild)
{
Puts("A guild has been updated!");
}
void Discord_GuildDelete(Guild guild)
{
Puts("A guild has been deleted!");
}
void Discord_GuildBanAdd(User user)
{
Puts("A user has been banned!");
}
void Discord_GuildBanRemove(User user)
{
Puts("A user has been unbanned!");
}
void Discord_GuildEmojisUpdate(GuildEmojisUpdate update)
{
Puts("The emoji's have been updated!");
}
void Discord_GuildIntergrationsUpdate(GuildIntergrationsUpdate update)
{
Puts("Guild Intergrations Updated!");
}
void Discord_MemberAdded(GuildMember member)
{
Puts("A user has been added to the server!");
}
void Discord_MemberRemoved(GuildMember member)
{
Puts("A user has been removed from the server!");
}
void Discord_GuildMemberUpdate(GuildMemberUpdate update, GuildMember oldMember)
{
Puts("A guild member has been updated!");
}
void Discord_GuildMembersChunk(GuildMembersChunk chunk)
{
Puts("A guild members chunk has been recieved!")
}
void Discord_GuildRoleCreate(Role role)
{
Puts("A new role has been created!");
}
void Discord_GuildRoleUpdate(Role newRole, Role oldRole)
{
Puts("A role has been updated!");
}
void Discord_GuildRoleDelete(Role role)
{
Puts("A role has been deleted!");
}
void Discord_MessageCreate(Message message)
{
Puts("A new message has been created!");
}
void Discord_MessageUpdate(Message message)
{
Puts("A message has been updated!");
}
void Discord_MessageDelete(MessageDelete message)
{
Puts("A message has been deleted!");
}
void Discord_MessageDeleteBulk(MessageDeleteBulk bulk)
{
Puts("A bulk of messages have been deleted!");
}
void Discord_MessageReactionAdd(MessageReactionUpdate update)
{
Puts("A reaction has been added to a message!");
}
void Discord_MessageReactionRemove(MessageReactionUpdate update)
{
Puts("A reaction has been removed from a message!");
}
void Discord_MessageReactionRemoveAll(MessageReactionRemoveAll reactions)
{
Puts("All reactions have been removed from a message!");
}
void Discord_PresenceUpdate(PResenceUpdate update)
{
Puts("Someone's presence has been updated!");
}
void Discord_TypingStart(TypingStart start)
{
Puts("Someone has started typing!");
}
void Discord_UserUpdate(User user)
{
Puts("A user has been updated!");
}
void Discord_VoiceStateUpdate(VoiceState state)
{
Puts("A users voice state has been updated!");
}
void Discord_VoiceServerUpdate(VoiceServerUpdate update)
{
Puts("The voice server has been updated!");
}
void Discord_WebhooksUpdate(WebhooksUpdate webhooks)
{
Puts("The webhooks have been updated!");
}
void Discord_UnhandledEvent(JObject messageObject)
{
Puts("An unhandlded event has occured!");
}
Want to contribute? Create a fork of the repo and create a pull request for any changes you wish to make!