Skip to content

Commit

Permalink
fix link category, fix duplicate channels
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlauer-Hax committed Jul 19, 2023
1 parent 452c0f0 commit fb6783c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActivityType, Client, Message, MessageType, REST, Routes } from 'discord.js'
import { ActivityType, CategoryChannel, Client, Message, MessageType, REST, Routes } from 'discord.js'
import { sendBanMessage, sendJoinMessage, sendLeaveMessage, sendPrivateMessage, sendVoice } from './helper';
import { handleInteraction } from "./interactions";
import DB from "./db";
Expand Down Expand Up @@ -109,12 +109,16 @@ client.on('voiceStateUpdate', sendVoice);

client.on('interactionCreate', (interaction) => handleInteraction(interaction, db));
client.on('messageCreate', async (message) => {
if (message.type === MessageType.GuildBoost && message.channelId === config.log_channel) {
if (message.type === MessageType.GuildBoost && message.channelId === config.log_channel && message.guild) {
const dbuser = await db.finduser(message.author.id);
if (!dbuser) {
const channel = await message.guild?.channels.create({
if (message.guild.channels.cache.find((channel) => channel.name === 'link-'+message.author.id)) {
await message.channel.send(`https://discord.com/channels/${message.guildId}/${message.channelId}/${message.id} already has a link channel`);
return;
}
const channel = await message.guild.channels.create({
name: 'link-'+message.author.id,
parent: config.link_category,
parent: await message.guild.channels.fetch(config.link_category) as CategoryChannel,
permissionOverwrites: [
{
id: message.author.id,
Expand All @@ -123,6 +127,7 @@ client.on('messageCreate', async (message) => {
]
});
await channel?.send({ content: `<@${message.author.id}> Looks like you just boosted the server! Unfortunately, you are not linked to your BBN account yet. Please send your Email address to this channel to link your account. Our Team will respond as soon as possible.`, allowedMentions: { users: [message.author.id] }});
await message.channel.send(`https://discord.com/channels/${message.guildId}/${message.channelId}/${message.id} created channel https://discord.com/channels/${message.guildId}/${channel?.id} to link`);
} else {
await db.addBoosterRewards(message.author.id);
await message.channel.send(`Added booster rewards for https://discord.com/channels/${message.guildId}/${message.channelId}/${message.id}`);
Expand Down

0 comments on commit fb6783c

Please sign in to comment.