https://github.com/agorlov/discordmsg
PHP Class to Send message to Discord channel (webhook)
https://github.com/agorlov/discordmsg
discord message php simple
Last synced: 6 months ago
JSON representation
PHP Class to Send message to Discord channel (webhook)
- Host: GitHub
- URL: https://github.com/agorlov/discordmsg
- Owner: agorlov
- License: mit
- Created: 2018-08-04T08:59:36.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-12-28T07:43:14.000Z (over 7 years ago)
- Last Synced: 2025-12-15T00:35:30.414Z (7 months ago)
- Topics: discord, message, php, simple
- Language: PHP
- Size: 9.77 KB
- Stars: 11
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Send message to Discord (php)
Very simple code to send single messages to discord channel.
This code was originally writen to send service messages
about deploying my project to production.
## How to Use
### Composer
Execute:
```bash
$ composer require agorlov/discordmsg
```
**Create** ``example.php``:
```php
send();
```
**Run it:**
```bash
$ php example.php
```
Check discord chanel (for tests), your message is there:
https://discord.gg/jB5FsPf
### Good old require_once
1. Put Msg.php and DiscordMsg.php to your project:
2. Check out how it works:
``example.php``
```php
require_once 'Msg.php';
require_once 'DiscordMsg.php';
echo "To see dumb messages..\n";
echo "..join the discordmsg chanel https://discord.gg/Bh4EZB and enjoy!\n";
echo "Feel free to test!\n";
// First message
$msg = new \AG\DiscordMsg('Hello, Friends');
$msg->send();
// Second message
(new \AG\DiscordMsg(
'I started the example.php, something happened?',
null,
$_ENV["USER"] ?? 'Mr. Pitkin'
))->send();
// Third message
(new \AG\DiscordMsg(
"Maybe the missile is launched? :grimacing:", // message
'https://discordapp.com/api/webhooks/475239272610398218/' . // chanel webhook link
'tfpeg5EFI_94oEHfltZwcB5UAurfcswkBw5mKouZCq-akhvxe5BNOtN16AqSHvmSwpum',
get_current_user(), // bot name
'' // avatar url
))->send();
```bash
$ php example.php
```
## How to notify user
Thank to @bricecarbou (https://github.com/agorlov/discordmsg/issues/3)
To notify anybody by webhook, we need to use the "real" id of user (recover in discord with @) and use $msg="<@id_recovered> ...
```php
$msg = "<@4386638385456546554> is notified";
(new \AG\DiscordMsg(
$msg, // message
$webhookurl, // chanel webhook link
"Trad Bot", // bot name
'' // avatar url
))->send();
```
## How to get Webhook link
Open chanel preferences (if you have enough permissions):

Create Webhook:
