Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/events/guildCreate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Client, EmbedBuilder, Guild, TextChannel } from "discord.js";
import {
ChannelType,
Client,
EmbedBuilder,
Guild,
PermissionFlagsBits,
TextChannel,
} from "discord.js";
import { ALStorage, loggingSystem } from "..";
export const name = "guildCreate";
export const execute = async (guild: Guild, client: Client) => {
Expand All @@ -12,6 +19,21 @@ export const execute = async (guild: Guild, client: Client) => {
.setTimestamp()
.setThumbnail(guild.iconURL())
.setFooter({ text: String(guild.id) });
const firstChannel = guild.channels.cache.find(
(c) =>
c.type === ChannelType.GuildText &&
c.permissionsFor(guild.members.me!).has(PermissionFlagsBits.SendMessages)
Copy link

Copilot AI Nov 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The guild.members.me may be null if the bot's member object hasn't been cached yet during the guildCreate event. The non-null assertion operator (!) could cause a runtime error. Consider checking if guild.members.me exists before calling permissionsFor, or wrap this in a try-catch block.

Suggested change
c.permissionsFor(guild.members.me!).has(PermissionFlagsBits.SendMessages)
guild.members.me !== null &&
c.permissionsFor(guild.members.me).has(PermissionFlagsBits.SendMessages)

Copilot uses AI. Check for mistakes.
);
if (firstChannel && firstChannel instanceof TextChannel) {
const thanksEmbed = new EmbedBuilder()
.setTitle("UniBotをご利用いただきありがとうございます :tada:")
.setDescription(
"サーバーに招待していただきありがとうございます!\nUniBotは皆様のサーバー運営を支援するために設計された多機能なDiscordボットです。\nサポートサーバーへもぜひお越しください: https://uniproject.jp/discord"
)
.setColor(client.config.color.success)
.setTimestamp();
await firstChannel.send({ embeds: [thanksEmbed] });
}
if (!channel || !(channel instanceof TextChannel)) {
logger.error(
{ extra_context: { channelId: client.config.logch.guildCreate } },
Expand Down