Skip to content

Commit

Permalink
fix: check for external role existence
Browse files Browse the repository at this point in the history
  • Loading branch information
Guilhermeasper committed Sep 16, 2023
1 parent 8dcf10e commit 7a93d24
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/events/guildMemberAdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ export const guildMemberAdd: BotEvent = {
throw new Error('Default channel not found');
}

defaultChannel.send(member.user.username + ' agora faz parte do motel!');
const role = member.guild.roles.cache.find(
(r) => r.id === guild.options.externalRoleId
await defaultChannel.send(
member.user.username + ' agora faz parte do motel!'
);
member.roles.add(role);

const externalRoleId = guild?.options?.externalRoleId;

if (!externalRoleId) {
throw new Error('External role not configured');
}

const role = member.guild.roles.cache.find((r) => r.id === externalRoleId);
await member.roles.add(role);
try {
member.send(
'Olá! Você foi colocado num cargo onde não é possível entrar em canais de voz. Favor contate um ' +
Expand All @@ -39,13 +46,15 @@ export const guildMemberAdd: BotEvent = {
throw new Error('Error sending message to user');
}

const admin = member.guild.members.cache
const guildMembers = await member.guild.members.fetch();

const admin = guildMembers
.filter((user) => user.id === member.guild.ownerId) // TODO: Add other admins to the filter
.first();

if (!admin) throw new Error('ADMIN NOT FOUND!!!');

admin.send(
await admin.send(
`O usuário ${member.user.username} entrou no servidor e quer se registrar!`
); // TODO: Improve this with buttons to accept or deny the user

Expand Down

0 comments on commit 7a93d24

Please sign in to comment.