Skip to content

Commit

Permalink
added methods to add and remove member roles
Browse files Browse the repository at this point in the history
  • Loading branch information
3ddelano committed Oct 2, 2021
1 parent 7491cd2 commit 4839d20
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Changelog
This is a high-level changelog for each released versions of the plugin.
For a more detailed list of past and incoming changes, see the commit history.

1.1.4
------
- Added `DiscordBot.get_guild_member()`
- Added `DiscordBot.add_member_role()`
- Added `DiscordBot.remove_member_role()`

1.1.3
------
- Updated `DiscordBot.send` to accept the channel_id or a `Message`
Expand Down
26 changes: 23 additions & 3 deletions addons/discord_gd/discord.gd
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var INTERACTION_TYPES = {'2': 'APPLICATION_COMMAND', '3': 'MESSAGE_COMPONENT'}

# Public Functions
func login() -> void:
assert(TOKEN.length() > 2, 'ERROR: Unable to login. TOKEN attribute not set.')
assert(TOKEN.length() > 10, 'ERROR: Unable to login. TOKEN attribute not set.')
_headers = [
'Authorization: Bot %s' % TOKEN,
'User-Agent: discord.gd (https://github.com/3ddelano/discord.gd)'
Expand Down Expand Up @@ -137,8 +137,13 @@ func get_guild_icon(guild_id: String, size: int = 256) -> PoolByteArray:

var guild = guilds.get(str(guild_id))

assert(guild, 'Guild not cached. Fetch guild first')
assert(guild.icon, 'Guild has no icon set.')
if not guild:
push_error('Guild not cached. Fetch guild first')
return

if not guild.icon:
push_error('Guild has no icon set.')
return

if size != 256:
assert(size in GUILD_ICON_SIZES, 'Invalid size for guild icon provided')
Expand All @@ -149,6 +154,21 @@ func get_guild_icon(guild_id: String, size: int = 256) -> PoolByteArray:
return png_bytes


func get_guild_member(guild_id: String, member_id: String) -> Dictionary:
var member = yield(_send_get('/guilds/%s/members/%s' % [guild_id, member_id]), 'completed')
return member


func remove_member_role(guild_id: String, member_id: String, role_id: String):
var res = yield(_send_get('/guilds/%s/members/%s/roles/%s' % [guild_id, member_id, role_id], HTTPClient.METHOD_DELETE), 'completed')
return res


func add_member_role(guild_id: String, member_id: String, role_id: String):
var res = yield(_send_request('/guilds/%s/members/%s/roles/%s' % [guild_id, member_id, role_id], {}, HTTPClient.METHOD_PUT), 'completed')
return res


func set_presence(p_options: Dictionary) -> void:
"""
p_options {
Expand Down
2 changes: 1 addition & 1 deletion addons/discord_gd/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="discord.gd"
description="A Discord bot API wrapper for Godot. "
author="Delano Lourenco"
version="1.1.3"
version="1.1.4"
script="plugin.gd"

0 comments on commit 4839d20

Please sign in to comment.