A simple Python script that sends, edits, or deletes a Discord message using either a bot token or a webhook URL, with the full payload defined in a local JSON file.
- Click here to view the website version
The script reads a Discord message payload from a local JSON file (message.json by default) and:
- Sends a new message to a channel (via bot or webhook).
- Edits an existing message (via bot or webhook).
- Deletes an existing message (via bot or webhook).
Because the entire payload comes from the JSON file, everything the Discord message API supports works out of the box: plain text, embeds, components (buttons, select menus), attachments, and more.
- Python 3.7+
- The
requestslibrary
Install dependencies with:
pip install requests- Go to the Discord Developer Portal.
- Click New Application, give it a name, and create it.
- Go to the Bot tab and click Add Bot.
- Copy the Bot Token — you'll need it.
- Under Privileged Gateway Intents, enable any intents you need (not required for simply sending messages).
- In the Developer Portal, go to OAuth2 → URL Generator.
- Select the
botscope. - Under Bot Permissions, select at minimum:
Send MessagesEmbed Links(if you plan to send embeds)Attach Files(if you plan to send attachments)Manage Messages(required to edit or delete messages sent by other users; not needed for the bot's own messages)Manage Channels(only needed if the bot will post in a locked/read-only channel)
- Copy the generated URL, open it in your browser, and add the bot to your server.
Warning
Avoid granting Administrator unless you fully trust the bot. It is not required for any feature of this script.
- In Discord, enable Developer Mode (User Settings → Advanced → Developer Mode).
- Right-click the channel you want to target and select Copy Channel ID.
- In Discord, open the target channel's settings → Integrations → Webhooks.
- Click New Webhook, name it, pick a channel, and copy the Webhook URL.
- Paste it into
WEBHOOK_URLin the script.
Open sendjson.py and replace the placeholders:
| Constant | Description |
|---|---|
CHANNEL_ID |
Target channel ID (bot mode). |
BOT_TOKEN |
Your bot token (bot mode). |
WEBHOOK_URL |
Webhook URL (webhook mode). Leave empty to use the bot. |
MESSAGE_ID |
Required for --edit and --delete. |
Warning
Never share your bot token or webhook URL, and never commit them to a public repository. Anyone with them can control your bot or webhook.
The script reads the entire Discord message payload from message.json. The contents are sent as-is.
Simple text example:
{
"content": "Hello, world!"
}Embed example:
{
"content": "Cool isn't it?",
"embeds": [
{
"title": "My Embed",
"description": "This is an embed sent by the bot.",
"color": 5814783
}
]
}Message with a button component:
{
"content": "Follow the Discord guidelines!",
"components": [
{
"type": 1,
"components": [
{
"type": 2,
"style": 5,
"label": "Visit Discord Guidelines",
"url": "https://discord.com/guidelines"
}
]
}
]
}For the full schema, see the Discord Message API documentation.
Send a new message (default):
python sendjson.pySend a new message explicitly:
python sendjson.py --sendEdit an existing message (requires MESSAGE_ID):
python sendjson.py --editDelete an existing message (requires MESSAGE_ID):
python sendjson.py --deleteForce webhook mode (overrides the bot token):
python sendjson.py --send --webhookUse a different payload file:
python sendjson.py --file other_message.jsonExpected output on success:
Message sent successfully!
On failure, the script prints the HTTP status code and the error response body from Discord.
Bot mode (--send, --edit, --delete):
POST https://discord.com/api/v10/channels/{CHANNEL_ID}/messagesPATCH https://discord.com/api/v10/channels/{CHANNEL_ID}/messages/{MESSAGE_ID}DELETE https://discord.com/api/v10/channels/{CHANNEL_ID}/messages/{MESSAGE_ID}
Authentication header: Authorization: Bot {BOT_TOKEN}.
Webhook mode:
POST {WEBHOOK_URL}PATCH {WEBHOOK_URL}/messages/{MESSAGE_ID}DELETE {WEBHOOK_URL}/messages/{MESSAGE_ID}
No Authorization header is used the webhook URL itself contains the token.
A 200, 201, or 204 response means the operation succeeded.
| Status Code | Meaning | Fix |
|---|---|---|
401 Unauthorized |
Invalid or missing bot token / webhook URL | Double-check BOT_TOKEN or WEBHOOK_URL |
403 Forbidden |
Bot lacks permission in that channel | Grant Send Messages (and Manage Messages for edit/delete on others' messages) |
404 Not Found |
Wrong channel ID, message ID, or webhook URL | Verify CHANNEL_ID, MESSAGE_ID, or WEBHOOK_URL |
400 Bad Request |
Malformed JSON payload | Validate message.json against the API docs |
429 Too Many Requests |
Rate limited | Wait and retry; Discord will tell you how long |
Do you think Discord™ is down? Click here for information. (copy status page url and paste it in new tab)
- The script runs once per invocation it does not stay running or listen for events.
--editreplaces the message content with whatever is in the JSON file. To keep existing fields, use Discord'sPATCHsemantics (only the fields you provide are changed).--deleteignores the JSON file entirely;MESSAGE_IDis the only input needed.- Webhooks cannot edit or delete arbitrary user messages only messages they posted.
- To change the message, edit
message.jsonno code changes required.