From b7ada53c1d88f0d8de680a5f7f9607f179ed7bda Mon Sep 17 00:00:00 2001 From: Tabby <41929769+tabby-cat-nya@users.noreply.github.com> Date: Fri, 7 Nov 2025 15:05:39 +1100 Subject: [PATCH] update to discord.gd 2.0.1 --- addons/discord_gd/classes/message.gd | 7 +++++-- addons/discord_gd/discord.gd | 18 +++++++----------- addons/discord_gd/plugin.cfg | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/addons/discord_gd/classes/message.gd b/addons/discord_gd/classes/message.gd index 01beb69..3d86e57 100644 --- a/addons/discord_gd/classes/message.gd +++ b/addons/discord_gd/classes/message.gd @@ -58,7 +58,7 @@ var MESSAGE_TYPES = { '22': 'GUILD_INVITE_REMINDER' } -func _init(message: Dictionary): +func _init(message: Dictionary, client = null): # Compulsory assert(typeof(message) == TYPE_DICTIONARY, 'Invalid type: message must be a Dictionary') assert(message.id, 'Message must have an id') @@ -81,7 +81,10 @@ func _init(message: Dictionary): pass else: # sent by user - assert(message.author is User, 'author attribute of Mesage must be of type User') + if not message.author is User: + message.author = User.new(client, message.author) + else: + assert(message.author is User, 'author attribute of Mesage must be of type User') author = message.author if message.has('flags'): diff --git a/addons/discord_gd/discord.gd b/addons/discord_gd/discord.gd index aab7a71..a529119 100644 --- a/addons/discord_gd/discord.gd +++ b/addons/discord_gd/discord.gd @@ -785,13 +785,9 @@ func _handle_events(dict: Dictionary) -> void: if d.sticker_items.size() != 0: return - var coroutine = await _parse_message(d) - if coroutine == null: - # message might be a thread - # TODO: Handle sending messages in threads - return + await _parse_message(d) - d = Message.new(d) + d = Message.new(d, self) var channel = channels.get(str(d.channel_id)) message_create.emit(self, d, channel) @@ -1222,6 +1218,10 @@ func _setup_heartbeat_timer(interval: int) -> void: func _send_dict_wss(d: Dictionary) -> void: + if _client.get_ready_state() != WebSocketPeer.STATE_OPEN: + if VERBOSE: + print("Failed to send packet as websocket state is not open. Got state: " + str(_client.get_ready_state())) + return var payload = JSON.stringify(d) var err = _client.put_packet(payload.to_utf8_buffer()) if OK != err: @@ -1294,11 +1294,7 @@ func _parse_message(message): channel = await _get_dm_channel(message.channel_id) _clean_channel(channel) - if channel and channel.has('type') and channel.type == 'DM': - channels[str(message.channel_id)] = channel - else: - # not a valid channel, it might be a thread - return null + channels[str(message.channel_id)] = channel if message.has('author') and typeof(message.author) == TYPE_DICTIONARY: # get the cached author of the message diff --git a/addons/discord_gd/plugin.cfg b/addons/discord_gd/plugin.cfg index 6dd0d2b..2b43695 100644 --- a/addons/discord_gd/plugin.cfg +++ b/addons/discord_gd/plugin.cfg @@ -3,5 +3,5 @@ name="discord.gd" description="A Discord bot API wrapper for Godot." author="Delano Lourenco" -version="2.0.0" +version="2.0.1" script="plugin.gd"