You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 18, 2023. It is now read-only.
Please read both sections as both have important information and both have advantages/disadvantages.
74
+
75
+
#### Webhook method
76
+
69
77
Now that you have registered commands, you can set up an HTTP server to listen for requests from Discord.
70
78
71
79
There are a few ways to set up an HTTP server to listen for requests:
72
80
- The built-in ReactPHP HTTP server.
73
-
- Using an external HTTP server such as Apache or nginx.
74
81
- Using the built-in ReactPHP HTTP server without HTTPS and using Apache or nginx as a reverse proxy (recommended).
82
+
- Using an external HTTP server such as Apache or nginx.
75
83
76
84
Whatever path you choose, the server **must** be protected with HTTPS - Discord will not accept regular HTTP.
77
85
@@ -122,7 +130,7 @@ $client->registerCommand('hello', function (Interaction $interaction, Choices $c
122
130
$client->run();
123
131
```
124
132
125
-
This library only handles slash commands, and there is no support for any other interactions with Discord such as creating channels, sending other messages etc. You can easily combine the DiscordPHP library with this library to have a much larger collection of tools. All you must do is ensure both clients share the same ReactPHP event loop. In the future, there will be more integration between the libraries. Here is an example:
133
+
This library only handles slash commands, and there is no support for any other interactions with Discord such as creating channels, sending other messages etc. You can easily combine the DiscordPHP library with this library to have a much larger collection of tools. All you must do is ensure both clients share the same ReactPHP event loop. Here is an example:
126
134
127
135
```php
128
136
<?php
@@ -145,11 +153,20 @@ $client = new Client([
145
153
'loop' => $discord->getLoop(),
146
154
]);
147
155
156
+
$client->linkDiscord($discord, false); // false signifies that we still want to use the HTTP server - default is true, which will use gateway
157
+
148
158
$discord->on('ready', function (Discord $discord) {
149
159
// DiscordPHP is ready
150
160
});
151
161
152
162
$client->registerCommand('my_cool_command', function (Interaction $interaction, Choices $choices) use ($discord) {
163
+
// there are a couple fields in $interaction that will return DiscordPHP parts:
164
+
$interaction->guild;
165
+
$interaction->channel;
166
+
$interaction->member;
167
+
168
+
// if you don't link DiscordPHP, it will simply return raw arrays
169
+
153
170
$discord->guilds->get('id', 'coolguild')->members->ban(); // do something ?
154
171
$interaction->acknowledge();
155
172
});
@@ -212,12 +229,50 @@ $ vim /etc/apache2/sites-available/000-default.conf # default site
212
229
SSLCertificateFile /path/to/ssl/cert.crt # change to your cert path
213
230
SSLCertificateKeyFile /path/to/ssl/cert.key # change to your key path
214
231
</VirtualHost>
215
-
```
232
+
```
216
233
3. Restart apache - the code below works on Debian-based systems:
217
234
```shell
218
235
$ sudo service apache2 restart
219
236
```
220
237
238
+
#### Gateway method (recommended)
239
+
240
+
The client can connect with a regular [DiscordPHP](https://github.com/discord-php/DiscordPHP) client to listen for interactions over gateway.
241
+
To use this method, make sure there is no interactions endpoint set in your Discord developer application.
242
+
243
+
Make sure you have included DiscordPHP into your project (at the time of writing, only DiscordPHP `develop` branch is supported):
0 commit comments