multiple welcome messages fix
This commit is contained in:
parent
56e2dcfff6
commit
849d98afda
@ -1,12 +1,26 @@
|
||||
import { ArgsOf, Discord, On } from 'discordx'
|
||||
import { EmbedBuilder, channelMention, userMention } from 'discord.js'
|
||||
import { EmbedBuilder, channelMention, userMention, User } from 'discord.js'
|
||||
import { db, DBTableEnum } from '../db'
|
||||
import { logger } from '../lib'
|
||||
|
||||
let lastJoinedUser: {
|
||||
username: string
|
||||
sent: boolean
|
||||
} = {
|
||||
username: '',
|
||||
sent: false,
|
||||
}
|
||||
|
||||
@Discord()
|
||||
export class GuildMemberAdd {
|
||||
@On({ event: 'guildMemberAdd' })
|
||||
async guildMemberAdd([member]: ArgsOf<'guildMemberAdd'>) {
|
||||
if (
|
||||
lastJoinedUser.username === member.user.username &&
|
||||
lastJoinedUser.sent
|
||||
)
|
||||
return
|
||||
|
||||
const portfolioChannelID = await db.get(DBTableEnum.PORTFOLIO_CHANNEL)
|
||||
const makeAnOrderChannelID = await db.get(
|
||||
DBTableEnum.MAKE_AN_ORDER_CHANNEL,
|
||||
@ -30,15 +44,25 @@ export class GuildMemberAdd {
|
||||
const role = await member.guild.roles.fetch(roleID)
|
||||
|
||||
if (channel && channel.isTextBased() && role) {
|
||||
channel.send({
|
||||
await channel
|
||||
.send({
|
||||
embeds: [embed],
|
||||
content: `What's up, ${userMention(member.id)}`,
|
||||
})
|
||||
.then(() => {
|
||||
lastJoinedUser = {
|
||||
username: member.user.username,
|
||||
sent: true,
|
||||
}
|
||||
})
|
||||
|
||||
try {
|
||||
await member.roles.add(role)
|
||||
} catch (e) {
|
||||
logger.error('Role is too high', 'Bot role must be higher than the role it gives')
|
||||
logger.error(
|
||||
'Role is too high',
|
||||
'Bot role must be higher than the role it gives',
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user