Discord Adapter
MaiBot's Discord platform adapter plugin, seamlessly bridging a Discord Bot with MaiBot through the Discord Gateway WebSocket. Supports Guild channels, DM chats, Threads, Reactions, and voice features.
Adapter Repository
Discord adapter source code: litroenade/MaiBot-Discord-Adapter
Create a Discord Bot
Before using the adapter, you need to create a Bot on Discord and obtain a Token.
Step 1: Create an Application and Bot
- Visit Discord Developer Portal
- Click New Application in the top right corner, enter an application name, and create it
- Click Bot in the left navigation bar
- Click Reset Token (or Add Bot), copy the Bot Token and save it securely
Step 2: Enable Privileged Gateway Intents
On the Bot page, scroll down to the Privileged Gateway Intents section and enable the following intents:
- Message Content Intent (required) — without this, the Bot cannot read message content
- Presence Intent (optional) — enable if you need to listen to user online status
- Server Members Intent (optional) — enable if you need to retrieve the full member list
Note
If Message Content Intent is not enabled, the Bot will not be able to read message text content, and connection.intent_message_content will not take effect even if set to true.
Step 3: Invite the Bot to a Server
- Click OAuth2 in the left navigation bar
- In the OAuth2 URL Generator, select:
- Scopes: check
bot - Bot Permissions: check as needed:
- Send Messages — send messages
- Read Message History — read message history (required for reply quoting)
- View Channels — view channels
- Add Reactions — add emoji reactions
- Connect — connect to voice channels (required for voice features)
- Speak — speak in voice channels (required for voice features)
- Attach Files — send attachments/images
- Scopes: check
- Copy the generated invitation link, open it in a browser, and select your server to complete the invitation
Permission Suggestions
If you need voice features, the Bot must also have View Channel, Connect, and Speak permissions for the target voice channel, otherwise it cannot join and play audio.
Step 4: Get Server/Channel IDs
Server ID and channel ID are needed for chat filtering configuration. Enable Developer Mode in Discord:
- Open Discord settings -> Advanced -> enable Developer Mode
- Right-click the server icon -> Copy Server ID
- Right-click the channel name -> Copy Channel ID
Installation
Clone the adapter repository into MaiBot's plugins/ directory:
cd /path/to/MaiBot/plugins
git clone https://github.com/litroenade/MaiBot-Discord-Adapter.gitYou can also install the plugin through MaiBot's WebUI.
Dependencies
maibot_sdk>= 2.0.0 (provided by MaiBot)discord.py>= 2.3.0discord-ext-voice-recv>= 0.4.1a139 (required for voice features)PyNaCl>= 1.5.0 (required for voice features)
Voice-related dependencies are installed automatically when voice features are enabled. If you only need text messaging, no additional installation is required.
Configuration
Enable the Adapter
The adapter is disabled by default after installation and needs to be manually enabled.
Method 1: Edit Configuration File
Edit plugins/MaiBot-Discord-Adapter/config.toml, set enabled to true and fill in the Bot Token:
[plugin]
enabled = true # Enable the adapter
config_version = "1.0.0"
[connection]
token = "Your Discord Bot Token" # RequiredThen restart MaiBot.
Method 2: Enable via WebUI
- Open MaiBot WebUI in a browser and log in with an Access Token
- Click "Plugin Management" in the left menu
- Find "Discord Adapter" and toggle the enable switch
- Fill in
connection.tokenin the configuration - Save the configuration and restart MaiBot (or wait for plugin hot reload)
Tip
Configuration can also be hot-reloaded via the WebUI plugin configuration page without restarting MaiBot.
Chat Filtering
The adapter enables chat list filtering by default, with the list mode set to blacklist (i.e., allows all sources by default). If you need to restrict the Bot to only respond to specific servers or channels, change the mode to whitelist and fill in the corresponding IDs:
[chat]
guild_list_type = "whitelist"
guild_list = ["Your Server ID"]
channel_list_type = "whitelist"
channel_list = ["Your Channel ID"]If the Bot is connected but not responding to messages, check the chat filtering configuration first.
Configuration Reference
[plugin] — Plugin Settings
enabled— Whether to enable the Discord adapter. When disabled, the plugin remains idle and does not establish a Discord connection. Default: falseconfig_version— Current configuration structure version (auto-maintained, no manual modification needed). Default: "1.0.0"
[connection] — Discord Connection
token— Discord Bot Token, copied from the Bot page in Developer Portal. Required when enabling the adapter. Default: emptyintent_messages— Server message permission (Guild Messages), controls server channel/thread messages. Default: trueintent_guilds— Server permission (retrieve server information). Default: trueintent_dm_messages— Direct message permission (Direct Messages), controls DM messages. Default: trueintent_message_content— Message content permission, must be enabled or message content cannot be read. Default: trueintent_voice_states— Voice state permission, required for voice features; can be disabled for text-only usage. Default: falseretry_delay— Reconnection retry interval (seconds). Default: 5connection_check_interval— Connection status check interval (seconds, recommended 30 seconds or more). Default: 30
[chat] — Chat Filtering
guild_list_type— Server list mode, options:whitelistorblacklist. Default: "blacklist"guild_list— Server ID list. Default: emptychannel_list_type— Channel list mode. Default: "blacklist"channel_list— Channel ID list. Default: emptythread_list_type— Thread list mode (ignored when inheriting channel permissions). Default: "blacklist"thread_list— Thread ID list. Default: emptyuser_list_type— User list mode. Default: "blacklist"user_list— User ID list. Default: emptyallow_thread_interaction— Whether to allow interaction in Threads. Default: trueinherit_channel_permissions— Whether threads inherit parent channel permissions. When enabled, if the parent channel is allowed, the thread is also allowed, and the thread list is ignored. Default: trueinherit_channel_memory— Whether threads inherit parent channel memory. When enabled, threads share context memory with the parent channel; when disabled, they are independent. Default: trueshow_typing_indicator— Whether to show Discord's "typing" indicator after receiving a processable message. Default: truetyping_indicator_delay_ms— Delay before showing the typing indicator (milliseconds), to avoid flashing on very fast replies. Default: 0typing_indicator_timeout_sec— Maximum duration to show the typing indicator (seconds). Set to 0 to never time out until a reply is sent. Default: 0
Chat Filtering Explanation
- Whitelist mode: only processes messages from servers/channels/users in the list; others are discarded
- Blacklist mode: processes all messages except those from servers/channels/users in the list
- All list modes default to blacklist (allow all). If the Bot is connected but not responding, check the list configuration first
[platform] — Platform Settings
platform_name— Platform identifier, used to distinguish different Discord instances in MaiBot. Must be unique when running multiple instances. Default: "discord"
[filters] — Message Filtering
ignore_self_message— Whether to ignore messages sent by the bot itself. Recommended to keep enabled to prevent the bot from processing its own messages. Default: trueignore_bot_message— Whether to ignore messages sent by other bots. Default: true
[voice] — Voice Features
enabled— Whether to enable voice features. When disabled, no voice manager is created and no voice channels are joined. Default: falsevoice_mode— Voice channel mode:fixedstays in a specified channel;autojoins when someone enters and leaves when empty. Default: "auto"fixed_channel_id— Voice channel ID for fixed mode (use the voice channel ID, not the category ID). Default: emptyauto_channel_list— Candidate voice channel ID list for auto mode; only listed voice channels will be joined/left automatically. Default: emptyidle_timeout_sec— Seconds to wait before leaving when empty in auto mode. Default: 300tts_provider— TTS voice synthesis provider, options:siliconflow/gptsovits/minimax. Default: "siliconflow"stt_provider— STT voice recognition provider, options:siliconflow_sensevoice/aliyun/tencent. Default: "siliconflow_sensevoice"enable_vad— Whether to enable volume-based Voice Activity Detection (VAD). Default: truevad_threshold_db— VAD volume threshold (dB). Values above this are considered as speaking. Range: approximately -60 (sensitive) to -30 (strict). Default: -50.0vad_deactivation_delay_ms— VAD deactivation delay (milliseconds), waits this long after the threshold is crossed to determine speech has stopped, to avoid splitting sentences. Default: 500send_text_in_voice— Whether to also send text to the voice channel text area when using TTS (for debugging). Default: false
Voice Prerequisites
Enabling voice features requires all of the following conditions:
voice.enabled = trueconnection.intent_voice_states = true- Bot has
View Channel,Connect, andSpeakpermissions for the target voice channel
[siliconflow_tts] — SiliconFlow TTS
Takes effect when voice.tts_provider is set to siliconflow.
api_key— SiliconFlow API key. Default: emptyapi_base— SiliconFlow API address. Default: "https://api.siliconflow.cn/v1"model— TTS model identifier. Default: "fnlp/MOSS-TTSD-v0.5"voice— TTS voice identifier. Default: "fnlp/MOSS-TTSD-v0.5:alex"sample_rate— Audio sample rate. opus only supports 48000; wav/pcm supports 8000/16000/24000/32000/44100; mp3 supports 32000/44100. Default: 32000speed— Speech speed (0.1 ~ 2.0). Default: 1.0response_format— Audio return format (mp3/opus/wav/pcm), wav recommended. Default: "wav"
[gptsovits_tts] — GPT-SoVITS TTS
Takes effect when voice.tts_provider is set to gptsovits.
api_base— GPT-SoVITS API address. Default: "http://127.0.0.1:8000"version— GPT-SoVITS service version. Default: "v4"model— Template model name, used for the infer_single template model interface. The config page will preferentially fetch template models from the local GSV server for selection. Default: emptyvoice— Template emotion/voice (optional), leave empty for automatic selection. Default: emptytext_lang— Synthesis language code. Default: "zh"response_format— Expected audio format, wav recommended. Default: "wav"speed_factor— Speech speed factor. Default: 1.0
About Template Models
The config page will preferentially fetch the template model list from the local GPT-SoVITS service's /models/{version} endpoint for selection. If fetching fails, you can also fill it in manually. Do not fill in OpenAI-compatible model IDs like GSVI-v4.
[minimax_tts] — MiniMax TTS
Takes effect when voice.tts_provider is set to minimax.
api_key— MiniMax API key. Default: emptyapi_base— MiniMax API address. Default: "https://api.minimax.io"model— TTS model. Default: "speech-2.8-hd"voice_id— Voice ID. Default: "male-qn-qingse"speed— Speech speed (0.5 ~ 2.0). Default: 1.0vol— Volume (0.1 ~ 2.0). Default: 1.0pitch— Pitch offset (-12 ~ 12). Default: 0.0audio_sample_rate— Output sample rate, options: 8000/16000/22050/24000/32000/44100. Default: 32000output_format— Audio encoding format (pcm/mp3/flac/wav). Default: "mp3"
[siliconflow_stt] — SiliconFlow STT
Takes effect when voice.stt_provider is set to siliconflow_sensevoice.
api_key— SiliconFlow API key. Default: emptyapi_base— SiliconFlow API address. Default: "https://api.siliconflow.cn/v1"model— STT model identifier. Default: "FunAudioLLM/SenseVoiceSmall"
[aliyun_stt] — Alibaba Cloud Speech Recognition
Takes effect when voice.stt_provider is set to aliyun.
access_key_id— Alibaba Cloud AccessKey ID. Default: emptyaccess_key_secret— Alibaba Cloud AccessKey Secret. Default: emptyapp_key— Intelligent Speech Interaction project App Key. Default: emptyregion— Service region. Default: "cn-shanghai"
[tencent_stt] — Tencent Cloud Speech Recognition
Takes effect when voice.stt_provider is set to tencent.
secret_id— Tencent Cloud SecretId. Default: emptysecret_key— Tencent Cloud SecretKey. Default: emptyengine— Recognition engine type. Default: "16k_zh"region— Service region. Default: "ap-shanghai"
Current Capabilities
Inbound Messages (Discord -> MaiBot)
- Guild channel messages
- DM private messages
- Thread messages
- Mentions, reply quoting, images, stickers
- Reaction add/remove events
- Optional speech-to-text (STT)
Outbound Messages (MaiBot -> Discord)
- Plain text
- Reply quoting
- User/role mentions
- Images and some attachments
- Reaction add/remove
- DM / Guild / Thread routing
- Optional text-to-speech (TTS)
Runtime Capabilities
- WebUI /
config.tomlconfiguration mapping - Connection status reporting
- Automatic reconnection and health check
- Thread context routing
- Discord platform message ID receipt writing
- Typing indicator
- Automatic splitting of long messages
Verify Connection
After starting MaiBot, check the following to confirm the adapter is working:
- MaiBot logs: seeing
Discord adapter startup task createdmeans the Bot has started connecting - MaiBot logs: no errors like
connection.token is emptyorDiscord client not ready - Message test: send a DM to the Bot in Discord or @mention the Bot in a channel and see if it replies
Common Issues
Bot does not connect to Discord after startup
- Check if
plugin.enabledis set totrue - Check if
connection.tokenis filled in correctly - Look for Token-related errors in the logs
Cannot receive messages in channels
- Confirm that Message Content Intent is enabled in Developer Portal
- Check if
connection.intent_message_contentistrue - Check the whitelist configuration in
chat.guild_listandchat.channel_list - Check if
filters.ignore_bot_messageis unintentionally blocking the target user
Cannot connect to Discord platform
- Discord services are not directly accessible from mainland China; a network proxy is required
- TUN mode proxy is recommended, with sing-box as the recommended proxy core
- Check if the proxy is working properly
Voice features not working
- Confirm that both
voice.enabledandconnection.intent_voice_statesare set totrue - Confirm that the Bot has
View Channel,Connect, andSpeakpermissions for the voice channel - Check if the TTS/STT provider's API key is valid
- Look for voice-related error messages in the logs
Thread messages not responding
- Check if
chat.allow_thread_interactionistrue - Check the
chat.inherit_channel_permissionsconfiguration: if the parent channel is not in the whitelist and inheritance is enabled, the thread will also be filtered