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:
- Shutdown the server.
- Open the server files, and navigate to the "Managed" folder (eg. "RustDedicated_Data/Managed")
- Download the latest release.
- Copy the "Oxide.Ext.Discord.dll" file into your "Managed" folder.
- 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:
- Visit the official Discord Developers page here: Discord Developer Documenation
- Click "New App".
- Name your app and click create! Note: A description isn't required.
- You will now be redirected to your created app, at the point you will need to click "Create a Bot User".
- Under the newly created bot section, under "Username" you will see "Token". Reveal the token and copy it into your plugin.
- 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, "<emoji_name:id>");
// Post the message to chat
server.Broadcast($"Discord Message: {message.author.username} - {message.content}");
}
}
}
void DiscordSocket_Initalized(DiscordClient client)
{
Puts("Client Initalized!");
}
- Called when the client is created, and the plugin can use it.
- No return behavior.
void DiscordSocket_HeartbeatSent()
{
Puts("Heartbeat sent to discord!");
}
- Called when a packet was sent to discord to keep up the connection.
- No return behavior.
void DiscordSocket_WebSocketOpened()
{
Puts("WebSocket Opened!");
}
- Called when the discord socket connects.
- No return behavior.
void DiscordSocket_WebSocketClosed(string reason, int code, bool clean)
{
Puts("WebSocket closed!");
}
- Called when the web socket is closed for any reason.
- No return behavior.
void DiscordSocket_WebSocketErrored(Exception exception, string message)
{
Puts($"WebSocket errored:.");
}
- Called when the web socket errors.
- No return behavior.
void Discord_Ready(Ready ready)
{
Puts("Discord is ready!");
}
- Called when discord is ready, and has started sending data.
void Discord_Resumed(Resumed resumed)
{
Puts("Discord Connection Resumed!");
}
- Called when the discord connection has been resumed.
void Discord_ChannelCreate(Channel channel)
{
Puts("Discord Channel Created");
}
- Called when a channel has been created.
void Discord_ChannelUpdate(Channel updatedChannel, Channel oldChannel)
{
Puts("Discord Channel Updated");
}
- Called when a channel has been updated.
void Discord_ChannelDelete(Channel channel)
{
Puts("Discord Channel Deleted!");
}
- Called when a discord channel has been deleted.
void Discord_ChannelPinsUpdate(ChannelPinsUpdate update)
{
Puts("The pins on a channel have been updated!");
}
- Called when the pins on a channel have been updated.
void Discord_GuildCreate(Guild guild)
{
Puts("A guild has been created!");
}
- Called when a new guild is created.
- This is not currently set up correctly.
void Discord_GuildUpdate(Guild guild)
{
Puts("A guild has been updated!");
}
- Called when a guild has been updated.
void Discord_GuildDelete(Guild guild)
{
Puts("A guild has been deleted!");
}
- Called when a guild is deleted.
void Discord_GuildBanAdd(User user)
{
Puts("A user has been banned!");
}
- Called when a user is banned.
void Discord_GuildBanRemove(User user)
{
Puts("A user has been unbanned!");
}
- Called when a user is unbanned.
void Discord_GuildEmojisUpdate(GuildEmojisUpdate update)
{
Puts("The emoji's have been updated!");
}
- Called when the emoji's in a guild have been updated.
void Discord_GuildIntergrationsUpdate(GuildIntergrationsUpdate update)
{
Puts("Guild Intergrations Updated!");
}
- Called when the intergrations in a guild have been updated?
void Discord_MemberAdded(GuildMember member)
{
Puts("A user has been added to the server!");
}
- Called when a user joins the discord server.
void Discord_MemberRemoved(GuildMember member)
{
Puts("A user has been removed from the server!");
}
- Called when a user is removed from the server.
void Discord_GuildMemberUpdate(GuildMemberUpdate update, GuildMember oldMember)
{
Puts("A guild member has been updated!");
}
- Called when a guild member is updated.
void Discord_GuildMembersChunk(GuildMembersChunk chunk)
{
Puts("A guild members chunk has been recieved!")
}
- Called in response to a 'Gateway Request Guild Members'.
void Discord_GuildRoleCreate(Role role)
{
Puts("A new role has been created!");
}
- Called when a new role is created
void Discord_GuildRoleUpdate(Role newRole, Role oldRole)
{
Puts("A role has been updated!");
}
- Called when a role is updated.
void Discord_GuildRoleDelete(Role role)
{
Puts("A role has been deleted!");
}
- Called when a role is deleted.
void Discord_MessageCreate(Message message)
{
Puts("A new message has been created!");
}
- Called when a new message is created.
void Discord_MessageUpdate(Message message)
{
Puts("A message has been updated!");
}
- Called when a message is updated.
void Discord_MessageDelete(MessageDelete message)
{
Puts("A message has been deleted!");
}
- Called when a message is deleted.
void Discord_MessageDeleteBulk(MessageDeleteBulk bulk)
{
Puts("A bulk of messages have been deleted!");
}
- Called when a bulk set of messages have been deleted.
void Discord_MessageReactionAdd(MessageReactionUpdate update)
{
Puts("A reaction has been added to a message!");
}
- Called when a reaction is added to a message.
void Discord_MessageReactionRemove(MessageReactionUpdate update)
{
Puts("A reaction has been removed from a message!");
}
- Called when a reaction is removed from a message.
void Discord_MessageReactionRemoveAll(MessageReactionRemoveAll reactions)
{
Puts("All reactions have been removed from a message!");
}
- Called when all reactions are removed from a message.
void Discord_PresenceUpdate(PResenceUpdate update)
{
Puts("Someone's presence has been updated!");
}
- Called when a user's presence is updated.
void Discord_TypingStart(TypingStart start)
{
Puts("Someone has started typing!");
}
- Called when someone starts typing.
void Discord_UserUpdate(User user)
{
Puts("A user has been updated!");
}
- Called when a user is updated.
void Discord_VoiceStateUpdate(VoiceState state)
{
Puts("A users voice state has been updated!");
}
- Called when a user's voice state is updated.
void Discord_VoiceServerUpdate(VoiceServerUpdate update)
{
Puts("The voice server has been updated!");
}
- Called when the voice server is updated.
void Discord_WebhooksUpdate(WebhooksUpdate webhooks)
{
Puts("The webhooks have been updated!");
}
- Called when the webhooks are updated.
void Discord_UnhandledEvent(JObject messageObject)
{
Puts("An unhandlded event has occured!");
}
- Called when an event that is not handlded by the extension was raised
- Please create an issue on the GitHub if this error ever occurs
Want to contribute? Create a fork of the repo and create a pull request for any changes you wish to make!