A Discord bot for managing FiveM TxAdmin accounts through slash commands.
This bot provides a secure interface for managing TxAdmin administrator accounts directly from Discord. It supports creating, editing, and deleting admin accounts with configurable permission groups and automatic logging.
- Secure authentication with TxAdmin API
- Role-based permission system
- Automatic action logging to Discord channels
- Type-safe implementation with TypeScript
- Configurable permission groups
- CSRF token-based security
| Command | Description | Required Parameters | Optional Parameters |
|---|---|---|---|
/createadmin |
Create new admin account | username, discord_user, group | citizenfx_id |
/editadmin |
Modify existing admin account | username, new_group | new_citizenfx_id, new_discord_user |
/deleteadmin |
Remove admin account | username | - |
- Node.js 18.0 or higher
- Running TxAdmin server instance
- Discord bot application with token
- Administrator permissions in Discord server
git clone <repository-url>
cd txadmin-discord-bot
npm installCreate a .env file in the project root:
# TxAdmin Server Configuration
TXADMIN_URL=http://localhost:40120
TXADMIN_USERNAME=admin
TXADMIN_PASSWORD=password
# Discord Bot Configuration
DISCORD_TOKEN=your_bot_token_here
DISCORD_GUILD_ID=your_guild_id_here
ADMIN_ROLE_ID=your_admin_role_id_here
# Optional: Logging Channels
CREATE_ADMIN_LOGS=channel_id
EDIT_ADMIN_LOGS=channel_id
DELETE_ADMIN_LOGS=channel_idConfigure admin permission groups in groups.json:
{
"groups": {
"admin": {
"name": "Administrator",
"description": "Full server access",
"permissions": [
"all_permissions",
"manage.admins",
"server.control"
]
},
"moderator": {
"name": "Moderator",
"description": "Limited moderation access",
"permissions": [
"players.kick",
"players.warn",
"players.message"
]
}
}
}- Navigate to the Discord Developer Portal
- Create a new application
- Navigate to the Bot section and create a bot
- Enable the following Privileged Gateway Intents:
- Server Members Intent
- Message Content Intent
- Copy the bot token to your
.envfile - Generate an OAuth2 URL with the following scopes:
applications.commandsbot
- Add the following bot permissions:
- Send Messages
- Embed Links
- Use Slash Commands
- Use the generated URL to invite the bot to your server
npm run devnpm run build
npm startsrc/
├── discord/
│ ├── commands/
│ │ ├── base.ts # Base command class
│ │ ├── create.ts # Create admin command
│ │ ├── edit.ts # Edit admin command
│ │ ├── delete.ts # Delete admin command
│ │ └── index.ts # Command exports
│ ├── bot.ts # Discord client and handler
│ ├── groups.ts # Permission group manager
│ ├── logger.ts # Channel logging system
│ ├── utils.ts # Utility functions
│ └── discord.ts # Module exports
├── txadmin/
│ └── txadmin.ts # TxAdmin API client
├── types/
│ └── types.ts # TypeScript type definitions
└── main/
└── main.ts # Application entry point
- All slash commands require Discord Administrator permissions by default
- Optional role-based access control through
ADMIN_ROLE_IDenvironment variable - Credentials are stored securely in environment variables
- CSRF token authentication with TxAdmin API
- Automatic session management and token refresh
- Verify the bot has the
applications.commandsscope - Ensure the bot has Administrator permissions in the server
- Global commands may take up to 1 hour to register
- Use
DISCORD_GUILD_IDfor instant guild-specific commands
- Confirm TxAdmin server is running and accessible
- Verify credentials in
.envfile are correct - Check TxAdmin URL includes the correct port number
- Ensure TxAdmin web interface is accessible from the bot's network
- Check bot is online in Discord
- Verify bot has necessary permissions in the server
- Review console logs for error messages
- Ensure all required environment variables are set
The TxAdminAPI class provides methods for interacting with the TxAdmin server:
createAdmin(adminData, permissions)- Create a new admin accounteditAdmin(username, adminData, permissions)- Modify an existing admin accountdeleteAdmin(username)- Remove an admin account
All methods return a Promise with success status and relevant data or error messages.
npm run buildnpm run type-checkMIT License - See LICENSE file for details
Contributions are welcome. Please open an issue or submit a pull request for any improvements or bug fixes.
For issues, questions, or feature requests, please open an issue on the GitHub repository.