### Command System Implementation (GDScript) Source: https://context7.com/3ddelano/discord-multiplayer-rpg-godot/llms.txt Example of a modular command script for the Discord bot. Commands extend a base `Command` class, define metadata in a `help` dictionary, and implement message handling in the `on_message` function. This example shows a 'ping' command. ```gdscript # cmds/ping.gd - Example command file extends Command func on_message(world, bot: DiscordBot, message: Message, channel: Dictionary, args: Array) -> void: var start = OS.get_ticks_msec() var msg = yield(bot.reply(message, "Pinging..."), "completed") var latency = OS.get_ticks_msec() - start yield(bot.edit(msg, "Pong! Latency: " + str(latency) + "ms"), "completed") func get_usage(p: String) -> String: return "`%sping`" % p var help = { "name": "ping", "category": "System", "aliases": ["p", "latency"], "enabled": true, "description": "Check the bot's response time" } ``` -------------------------------- ### Get Discord User Information and Avatar (GDScript) Source: https://context7.com/3ddelano/discord-multiplayer-rpg-godot/llms.txt This GDScript snippet shows how to retrieve information about a Discord user, such as username, discriminator, ID, and bot status. It also demonstrates fetching the user's avatar URL with various options and as raw byte data. ```gdscript func _on_message_create(bot: DiscordBot, message: Message, channel: Dictionary): var author: User = message.author # Get user info print("Username: " + author.username) print("Discriminator: " + author.discriminator) print("User ID: " + author.id) print("Is Bot: " + str(author.bot)) # Get avatar URL with options var avatar_url = author.get_display_avatar_url({ "format": "png", # webp, png, jpg, jpeg, gif "size": 256, # 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 "dynamic": true # Auto-detect animated avatars }) # Get avatar as bytes (for processing/saving) var avatar_bytes = yield(author.get_display_avatar({ "format": "png", "size": 128 }), "completed") # Get default avatar URL (for users without custom avatar) var default_url = author.get_default_avatar_url() ``` -------------------------------- ### Message Reactions Management (GDScript) Source: https://context7.com/3ddelano/discord-multiplayer-rpg-godot/llms.txt Functions for adding and removing reactions on Discord messages. Supports custom emoji IDs only. Operations are asynchronous and require yielding. Includes functions to get users who reacted. ```gdscript # Add a reaction to a message (custom emoji ID only) func add_reaction(bot: DiscordBot, message: Message, emoji_id: String): var status = yield(bot.create_reaction(message, emoji_id), "completed") print("Reaction added, status: " + str(status)) # Remove bot's reaction func remove_own_reaction(bot: DiscordBot, message: Message, emoji_id: String): yield(bot.delete_reaction(message, emoji_id), "completed") # Remove another user's reaction func remove_user_reaction(bot: DiscordBot, message: Message, emoji_id: String, user_id: String): yield(bot.delete_reaction(message, emoji_id, user_id), "completed") # Remove all reactions for a specific emoji func remove_emoji_reactions(bot: DiscordBot, message: Message, emoji_id: String): yield(bot.delete_reactions(message, emoji_id), "completed") # Remove all reactions from a message func remove_all_reactions(bot: DiscordBot, message: Message): yield(bot.delete_reactions(message), "completed") # Get users who reacted with a specific emoji func get_reactors(bot: DiscordBot, message: Message, emoji_id: String): var users = yield(bot.get_reactions(message, emoji_id), "completed") for user in users: print("User reacted: " + user.username) ``` -------------------------------- ### Initialize and Login Discord Bot in GDScript Source: https://github.com/3ddelano/discord-multiplayer-rpg-godot/blob/main/addons/discord_gd/README.md This GDScript snippet demonstrates how to initialize the DiscordBot node, set the bot token, and log in to Discord. It connects to the `bot_ready` signal to confirm successful login and prints bot information. ```GDScript extends Node2D func _ready(): var discord_bot = $DiscordBot discord_bot.TOKEN = "your_bot_token_here" discord_bot.login() func _on_DiscordBot_bot_ready(bot: DiscordBot): print('Logged in as ' + bot.user.username + '#' + bot.user.discriminator) print('Listening on ' + str(bot.channels.size()) + ' channels and ' + str(bot.guilds.size()) ' guilds.') ``` -------------------------------- ### Discord Bot Initialization and Event Handling (GDScript) Source: https://context7.com/3ddelano/discord-multiplayer-rpg-godot/llms.txt This snippet demonstrates the initialization of the DiscordBot class, setting up essential parameters like the bot token and intents. It also shows how to connect to various bot events such as readiness, message creation, and interaction handling, which are crucial for bot operation. ```gdscript extends Node2D func _ready(): var bot = $DiscordBot bot.TOKEN = "your_bot_token_here" bot.INTENTS = 513 # Default: GUILDS and GUILD_MESSAGES bot.VERBOSE = false # Connect to signals bot.connect("bot_ready", self, "_on_bot_ready") bot.connect("message_create", self, "_on_message_create") bot.connect("interaction_create", self, "_on_interaction_create") bot.connect("guild_create", self, "_on_guild_create") bot.connect("message_delete", self, "_on_message_delete") # Login to Discord bot.login() func _on_bot_ready(bot: DiscordBot): print("Logged in as " + bot.user.username + "#" + bot.user.discriminator) print("Connected to " + str(bot.guilds.size()) + " guilds") print("Listening on " + str(bot.channels.size()) + " channels") func _on_message_create(bot: DiscordBot, message: Message, channel: Dictionary): if message.author.bot: return print("Message from " + message.author.username + ": " + message.content) ``` -------------------------------- ### Display User Profile Command (Godot) Source: https://context7.com/3ddelano/discord-multiplayer-rpg-godot/llms.txt Implements a Discord bot command to display a user's profile information using embeds. It retrieves user data like avatar, ID, and discriminator, then formats it into a rich embed message. Dependencies include the DiscordBot and Message objects from the Discord.gd plugin. ```gdscript extends Command func on_message(world, bot: DiscordBot, message: Message, channel: Dictionary, args: Array) -> void: var target_user = message.author var avatar_url = target_user.get_display_avatar_url({"size": 128}) var embed = Embed.new() embed.set_title(target_user.username + "'s Profile") embed.set_thumbnail(avatar_url) embed.set_color("#3498db") embed.add_field("User ID", target_user.id, true) embed.add_field("Discriminator", "#" + target_user.discriminator, true) embed.set_timestamp() bot.send(message, {"embeds": [embed]}) var help = { "name": "profile", "category": "User", "enabled": true, "description": "Display user profile information" } ``` -------------------------------- ### Discord Interactive Buttons and Action Rows (GDScript) Source: https://context7.com/3ddelano/discord-multiplayer-rpg-godot/llms.txt This code demonstrates the creation and configuration of interactive buttons for Discord messages using MessageButton and MessageActionRow. It covers different button styles (primary, danger, link, secondary), setting labels, custom IDs, URLs, and disabling buttons, enabling user interaction through clickable elements. ```gdscript # Create buttons with different styles var primary_btn = MessageButton.new() primary_btn.set_style(MessageButton.STYLES.PRIMARY) primary_btn.set_label("Accept") primary_btn.set_custom_id("btn_accept") var danger_btn = MessageButton.new() danger_btn.set_style(MessageButton.STYLES.DANGER) danger_btn.set_label("Cancel") danger_btn.set_custom_id("btn_cancel") var link_btn = MessageButton.new() link_btn.set_style(MessageButton.STYLES.LINK) link_btn.set_label("Visit Website") link_btn.set_url("https://example.com") var disabled_btn = MessageButton.new() disabled_btn.set_style(MessageButton.STYLES.SECONDARY) disabled_btn.set_label("Unavailable") disabled_btn.set_custom_id("btn_disabled") disabled_btn.set_disabled(true) ``` -------------------------------- ### Create and Send Message with Action Row and Buttons (GDScript) Source: https://context7.com/3ddelano/discord-multiplayer-rpg-godot/llms.txt This snippet demonstrates how to create an action row, add buttons to it, and then send a message containing this action row. It's useful for creating interactive messages in Discord. ```gdscript var row = MessageActionRow.new() row.add_component(primary_btn) row.add_component(danger_btn) row.add_component(link_btn) bot.send(message, { "content": "Choose an option:", "components": [row] }) ``` -------------------------------- ### Set Discord Bot Presence and Activity (GDScript) Source: https://context7.com/3ddelano/discord-multiplayer-rpg-godot/llms.txt This GDScript snippet demonstrates how to configure the bot's online status and activity using the `set_presence()` method. It allows setting the status to online, idle, dnd, etc., and defining the type and name of the activity (e.g., playing a game). ```gdscript func _on_bot_ready(bot: DiscordBot): # Set playing status bot.set_presence({ "status": "online", # online, dnd, idle, invisible, offline "afk": false, "activity": { "type": "GAME", # GAME, STREAMING, LISTENING, WATCHING, COMPETING "name": ".help | Godot Engine" } }) ``` -------------------------------- ### Create Discord Thread (Godot) Source: https://context7.com/3ddelano/discord-multiplayer-rpg-godot/llms.txt Demonstrates how to create a new thread from a message in Discord using the DiscordBot object. It allows specifying a thread name and an auto-archive duration. The function returns a completed thread object upon successful creation. ```gdscript # Start a thread from a message func create_thread(bot: DiscordBot, message: Message): var thread = yield(bot.start_thread(message, "Discussion Thread", 60 * 24), "completed") # duration is in minutes: 60 = 1 hour, 60*24 = 1 day, 60*24*3 = 3 days, 60*24*7 = 1 week print("Thread created: " + thread.name) print("Thread ID: " + thread.id) ``` -------------------------------- ### Discord Embed Creation and Usage (GDScript) Source: https://context7.com/3ddelano/discord-multiplayer-rpg-godot/llms.txt This snippet focuses on creating rich embeds for Discord messages using the Embed class. It demonstrates setting various embed properties like title, description, color, author, image, footer, and fields, showcasing how to enhance message content with structured information. ```gdscript # Create a rich embed var embed = Embed.new() embed.set_title("Game Status") embed.set_description("Welcome to the RPG game!") embed.set_color("#f2b210") # Supports hex colors embed.set_timestamp() embed.set_author("Game Bot", "https://example.com", "https://example.com/icon.png") embed.set_thumbnail("https://example.com/thumb.png") embed.set_image("attachment://screenshot.png") embed.set_footer("Powered by Discord.gd", "https://example.com/footer.png") embed.add_field("Level", "5", true) embed.add_field("XP", "1250/2000", true) embed.add_field("Gold", "500", true) # Send message with embed bot.send(message, { "embeds": [embed] }) # Embed with color as RGB array var rgb_embed = Embed.new() rgb_embed.set_color([255, 128, 0]) # Orange color rgb_embed.set_title("RGB Color Example") ``` -------------------------------- ### Discord Message Sending and Manipulation (GDScript) Source: https://context7.com/3ddelano/discord-multiplayer-rpg-godot/llms.txt This code illustrates how to send, reply to, edit, and delete messages using the Discord.gd plugin. It covers basic text messages, replies, and messages with advanced options like text-to-speech and allowed mentions, demonstrating fundamental bot communication capabilities. ```gdscript # Send a simple text message to a channel var msg = yield(bot.send(channel_id, "Hello, Discord!"), "completed") # Reply to a message var reply = yield(bot.reply(message, "This is a reply!"), "completed") # Send message with options var options_msg = yield(bot.send(message, { "content": "Message with options", "tts": false, "allowed_mentions": { "parse": ["users"], "replied_user": true } }), "completed") # Edit a message var edited = yield(bot.edit(msg, "Updated content!"), "completed") # Delete a message yield(bot.delete(msg), "completed") ``` -------------------------------- ### Send File Attachments with Discord Messages (GDScript) Source: https://context7.com/3ddelano/discord-multiplayer-rpg-godot/llms.txt This GDScript code illustrates how to send files, such as images or JSON data, as attachments to Discord messages. It covers saving an image to a buffer and sending it with an embed, as well as sending multiple files of different types. ```gdscript # Send an image file with a message func send_screenshot(bot: DiscordBot, message: Message, image: Image): var png_bytes = image.save_png_to_buffer() var embed = Embed.new() embed.set_title("Game Screenshot") embed.set_image("attachment://screenshot.png") embed.set_timestamp() yield(bot.send(message, { "embeds": [embed], "files": [{ "name": "screenshot.png", "media_type": "image/png", "data": png_bytes }] }), "completed") # Send multiple files func send_multiple_files(bot: DiscordBot, channel_id: String): var file1 = File.new() file1.open("res://assets/image1.png", File.READ) var data1 = file1.get_buffer(file1.get_len()) file1.close() yield(bot.send(channel_id, { "content": "Here are multiple files:", "files": [ {"name": "image1.png", "media_type": "image/png", "data": data1}, {"name": "data.json", "media_type": "application/json", "data": '{"key": "value"}'.to_utf8()} ] }), "completed") ``` -------------------------------- ### Handle Discord Button Interactions (GDScript) Source: https://context7.com/3ddelano/discord-multiplayer-rpg-godot/llms.txt This GDScript code handles various button interactions from Discord messages. It shows how to reply, defer, update, and follow up on interactions based on the button's custom ID. It requires a DiscordBot and DiscordInteraction object. ```gdscript func _on_interaction_create(bot: DiscordBot, interaction: DiscordInteraction): # Check if it's a button interaction if not interaction.is_button(): return var custom_id = interaction.data.custom_id var user_id = interaction.member.user.id match custom_id: "btn_accept": # Reply to the interaction (ephemeral = only visible to user) yield(interaction.reply({ "content": "You accepted!", "ephemeral": true }), "completed") "btn_cancel": # Update the original message yield(interaction.update({ "content": "Action cancelled.", "components": [] # Remove buttons }), "completed") "btn_process": # Defer the reply (show "thinking..." state) yield(interaction.defer_reply(), "completed") # Do some processing... yield(get_tree().create_timer(2.0), "timeout") # Edit the deferred reply yield(interaction.edit_reply({ "content": "Processing complete!" }), "completed") # Follow-up messages after initial reply func send_follow_up(interaction: DiscordInteraction): var follow_up_msg = yield(interaction.follow_up({ "content": "This is a follow-up message!" }), "completed") # Edit the follow-up yield(interaction.edit_follow_up(follow_up_msg, { "content": "Updated follow-up!" }), "completed") # Delete the follow-up yield(interaction.delete_follow_up(follow_up_msg), "completed") ``` -------------------------------- ### Guild and Channel Operations (GDScript) Source: https://context7.com/3ddelano/discord-multiplayer-rpg-godot/llms.txt Functions for interacting with Discord guilds and channels, including accessing cached data, fetching guild icons and emojis, retrieving members, creating direct message channels, and managing member roles. These operations are asynchronous and require yielding. ```gdscript # Access cached data func show_guild_info(bot: DiscordBot, guild_id: String): var guild = bot.guilds.get(guild_id) if guild: print("Guild Name: " + guild.name) print("Owner ID: " + guild.owner_id) print("Member Count: " + str(guild.members.size())) # Get guild icon as bytes func get_guild_icon(bot: DiscordBot, guild_id: String): var icon_bytes = yield(bot.get_guild_icon(guild_id, 256), "completed") # icon_bytes is PoolByteArray of PNG data # Get guild emojis func list_emojis(bot: DiscordBot, guild_id: String): var emojis = yield(bot.get_guild_emojis(guild_id), "completed") for emoji in emojis: print("Emoji: " + emoji.name + " ID: " + emoji.id) # Get a specific guild member func get_member(bot: DiscordBot, guild_id: String, user_id: String): var member = yield(bot.get_guild_member(guild_id, user_id), "completed") print("Nickname: " + str(member.nick)) print("Roles: " + str(member.roles)) # Create a DM channel func send_dm(bot: DiscordBot, user_id: String): var dm_channel = yield(bot.create_dm_channel(user_id), "completed") yield(bot.send(dm_channel.id, "Hello via DM!"), "completed") # Manage member roles func manage_roles(bot: DiscordBot, guild_id: String, member_id: String, role_id: String): yield(bot.add_member_role(guild_id, member_id, role_id), "completed") yield(bot.remove_member_role(guild_id, member_id, role_id), "completed") ``` -------------------------------- ### Set Bot Presence Status (GDScript) Source: https://context7.com/3ddelano/discord-multiplayer-rpg-godot/llms.txt Functions to set the bot's presence status and activity on Discord. This includes streaming, listening, and other activity types. Requires a DiscordBot instance. ```gdscript func set_streaming(bot: DiscordBot): bot.set_presence({ "status": "online", "activity": { "type": "STREAMING", "name": "Live Development", "url": "https://twitch.tv/example" } }) func set_listening(bot: DiscordBot): bot.set_presence({ "status": "dnd", "activity": { "type": "LISTENING", "name": "user commands" } }) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.