Skip to content

Commit 00a1493

Browse files
committed
Clarify usage of getPrivateChannel
1 parent 2d3501b commit 00a1493

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,32 +80,34 @@ class Guild extends Eloquent
8080
```
8181

8282
> **NOTE**: Discord handles direct messages as though they are a regular channel. If you wish to allow users to receive direct messages from your bot, you will need to create a private channel with that user.
83+
>
8384
> An example workflow may look like the following:
8485
>
85-
> 1. Your `users` table has two discord columns: `discord_user` and `discord_channel`
86-
> 2. When a user updates their Discord user ID (`discord_user`), generate and save a channel ID (`discord_channel`)
87-
> 3. Return the user's `discord_channel` in the `routeNotificationForDiscord` method on the User model
86+
> 1. Your `users` table has two discord columns: `discord_user_id` and `discord_private_channel_id`
87+
> 2. When a user updates their Discord user ID (`discord_user_id`), generate and save a private channel ID (`discord_private_channel_id`)
88+
> 3. Return the user's `discord_private_channel_id` in the `routeNotificationForDiscord` method on the `User` model
8889
>
89-
> You can generate direct message channels by using the `getPrivateChannel` method in `NotificationChannels\Discord\Discord`:
90+
> You can generate direct message channels by using the `getPrivateChannel` method in the `NotificationChannels\Discord\Discord` class
9091
>
9192
> ```php
9293
> use NotificationChannels\Discord\Discord;
93-
> // ...
9494
>
9595
> class UserDiscordSettingsController
9696
> {
9797
> public function store(Request $request)
9898
> {
99-
> $user = $request->input('discord_user');
100-
> $channel = app(Discord::class)->getPrivateChannel($user);
99+
> $userId = $request->input('discord_user_id');
100+
> $channelId = app(Discord::class)->getPrivateChannel($userId);
101101
>
102102
> Auth::user()->update([
103-
> 'discord_user' => $user,
104-
> 'discord_channel' => $channel,
103+
> 'discord_user_id' => $userId,
104+
> 'discord_private_channel_id' => $channelId,
105105
> ]);
106106
> }
107107
> }
108108
> ```
109+
>
110+
> Please take note that the `getPrivateChannel` method only accepts [Discord's snowflake IDs](https://discordapp.com/developers/docs/reference#snowflakes). There is no API route provided by Discord to lookup a user's ID by their name and tag, and the process for copying and pasting a user ID can be confusing to some users. Because of this, it is recommended to add the option for users to connect their Discord account to their account within your application either by logging in with Discord or linking it to their pre-existing account.
109111
110112
You may now tell Laravel to send notifications to Discord channels in the `via` method:
111113

src/Discord.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ public function send($channel, array $data)
5555
}
5656

5757
/**
58-
* Create and/or get a private channel with a Discord user.
58+
* Get a private channel with another Discord user from their snowflake ID.
5959
*
60-
* @param mixed $user
60+
* @param string $userId
6161
*
6262
* @return string
6363
*/
64-
public function getPrivateChannel($user)
64+
public function getPrivateChannel($userId)
6565
{
66-
return $this->request('POST', 'users/@me/channels', ['recipient_id' => $user])['id'];
66+
return $this->request('POST', 'users/@me/channels', ['recipient_id' => $userId])['id'];
6767
}
6868

6969
/**

0 commit comments

Comments
 (0)