Overview
Sakuya AC supports real-time chat synchronization between Discord and your YSFlight server. Players can communicate across platforms, with messages automatically relayed in both directions.Discord messages appear in-game with the
[Discord] prefix, and in-game messages are sent to your configured Discord channel.Features
- Bidirectional messaging - Discord ↔ YSFlight chat sync
- Automatic @mention sanitization - Prevents @everyone and @here abuse
- Bot message filtering - Ignores messages from other bots
- Player join/leave notifications - Discord alerts when players connect/disconnect
- Non-blocking operation - Runs asynchronously without impacting server performance
Prerequisites
Python Dependencies
Discord integration requires additional Python packages:On modern Linux distributions, you may need to create a virtual environment:
Required Dependencies
The integration uses:aiohttp- Asynchronous HTTP client for Discord APIasyncio- Async runtime (included in Python 3.7+)
Setting Up Discord Bot
Create Discord Application
- Go to Discord Developer Portal
- Click New Application
- Enter a name (e.g., “YSFlight Chat Bot”)
- Click Create
Create Bot User
- Navigate to the Bot section in the left sidebar
- Click Add Bot
- Confirm by clicking Yes, do it!
- Customize the bot’s username and avatar if desired
Configure Bot Permissions
Enable the Message Content Intent:
- Scroll to Privileged Gateway Intents
- Enable Message Content Intent
- Click Save Changes
Get Bot Token
- In the Bot section, find the Token area
- Click Reset Token (or Copy if visible)
- Copy the token and save it securely
Invite Bot to Server
- Go to OAuth2 > URL Generator
- Select scopes:
bot
- Select bot permissions:
Read Messages/View ChannelsSend MessagesRead Message History
- Copy the generated URL and open it in your browser
- Select your server and authorize
Configuration
Edit yourconfig.py file with the Discord settings:
config.py
Set to
True to enable Discord integration, False to disable.Your Discord bot token from the Developer Portal.
The Discord channel ID where messages will be synchronized.
How It Works
Message Flow
Discord → YSFlight:Player Notifications
When players join or leave, Discord receives notifications:Security Features
@mention Sanitization
@mention Sanitization
The integration automatically removes This prevents Discord users from spamming mass mentions through the game chat.
@everyone and @here mentions from Discord messages before relaying them to the game:Bot Message Filtering
Bot Message Filtering
Messages from bots (including the integration bot itself) are automatically ignored to prevent message loops:
Implementation Details
Discord API Communication
The integration uses Discord’s REST API (v10) with the following endpoints: Sending Messages:Polling Mechanism
The system polls Discord every 1 second for new messages:This polling interval balances responsiveness with API rate limits. You can adjust it in
lib/discordSync.py:98 if needed.Broadcasting to Players
When a Discord message is received, it’s broadcast to all connected players:Troubleshooting
Bot not receiving messages
Message Content Intent not enabled
Message Content Intent not enabled
Verify in the Developer Portal:
- Go to your application
- Navigate to Bot
- Scroll to Privileged Gateway Intents
- Ensure Message Content Intent is enabled
- Save changes and restart your server
Incorrect bot token
Incorrect bot token
Check your
DISCORD_TOKEN in config.py:- Tokens should be 70+ characters long
- They contain letters, numbers, and special characters
- If unsure, reset the token in the Developer Portal
Wrong channel ID
Wrong channel ID
Verify your
CHANNEL_ID:- Channel IDs are 17-19 digit numbers
- Must be an integer, not a string
- The bot must have access to this channel
Bot not sending messages
Missing permissions
Missing permissions
Ensure the bot has these permissions in the channel:
- Read Messages/View Channels
- Send Messages
- Read Message History
API errors in logs
API errors in logs
Check your server logs for Discord API errors:Common errors:
401 Unauthorized- Invalid token403 Forbidden- Missing permissions404 Not Found- Invalid channel ID
Dependencies not installing
Linux virtual environment required
Linux virtual environment required
Modern Linux distros require virtual environments:
Python version too old
Python version too old
The integration requires Python 3.7+ for If you have an older version, upgrade Python before installing dependencies.
asyncio support:Performance Considerations
- Asynchronous operation: Discord integration runs in the background without blocking game packets
- Connection pooling: Uses
aiohttpsession pooling for efficient API requests - Player cleanup: Disconnected players are automatically removed from broadcast lists
- Rate limiting: 1-second polling interval respects Discord’s rate limits
Security Best Practices
Protect Your Token
Never commit
DISCORD_TOKEN to version control. Use environment variables or a separate credentials file that’s gitignored.Limit Bot Permissions
Only grant the minimum required permissions. The bot doesn’t need administrator rights.
Monitor API Usage
Discord has rate limits. If you experience issues, check the polling interval in
discordSync.py.Use Read-Only Roles
Consider creating a read-only role for the bot in sensitive channels to prevent accidental message sends.
Advanced Configuration
Custom Message Formatting
To customize how Discord messages appear in-game, editlib/discordSync.py:84:
Adjust Polling Rate
To change how often Discord is checked for new messages, modifylib/discordSync.py:98: