Skip to content

Commit 03fbbf4

Browse files
committed
(bugfig) always fetch the owner before trying to DM them on join. Fixes possible null reference
1 parent f340cf6 commit 03fbbf4

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

main.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ function onReady() {
123123
* Event handler for when the bot joins a new guild.
124124
*/
125125
function onGuildJoin(guild) {
126+
let info = unindent(`Hi there! My role needs to be ordered above any
127+
role you would like me to assign. You're getting this message
128+
because you are the server owner, but anybody with Administrator
129+
permissions or an allowed role can configure me.`);
130+
126131
guild.members.fetch(client.user.id)
127132
.then(clientMember => {
128-
let info = unindent(`Hi there! My role needs to be ordered above any
129-
role you would like me to assign. You're getting this message
130-
because you are the server owner, but anybody with Administrator
131-
permissions or an allowed role can configure me.`);
132-
133133
const Perms = Discord.Permissions.FLAGS;
134134
const requiredPermMap = {
135135
[Perms.ADD_REACTIONS]: 'Add Reactions',
@@ -157,9 +157,10 @@ function onGuildJoin(guild) {
157157
'\n' + missingPermNames.join('\n');
158158
}
159159

160-
return guild.owner.createDM()
161-
.then(dmChannel => dmChannel.send(info));
160+
return guild.members.fetch(guild.ownerID);
162161
})
162+
.then(owner => owner.createDM())
163+
.then(dmChannel => dmChannel.send(info))
163164
.catch(logError);
164165
}
165166

0 commit comments

Comments
 (0)