Skip to content

Commit

Permalink
main
Browse files Browse the repository at this point in the history
  • Loading branch information
tensandev committed Jan 5, 2025
1 parent 84a7829 commit 68a193d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ojisan_aisatsu_bot/.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
TOKEN=あなたのBotトークン
TOKEN=
7 changes: 6 additions & 1 deletion ojisan_aisatsu_bot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@ client.once('ready', () => {

// ユーザーがサーバーに参加したときの処理
client.on('guildMemberAdd', (member) => {
// ニックネームがある場合はそれを使用、ない場合はユーザー名を使用
const username = member.nickname || member.user.username;

// ランダムに挨拶構文を選択
const randomGreeting = greetings[Math.floor(Math.random() * greetings.length)];

// {user} をユーザー名で置き換え
const message = randomGreeting.replace('{user}', member.user.username);
const message = randomGreeting.replace(/{user}/g, username);

// サーバーの一般チャンネルで挨拶
const channel = member.guild.systemChannel; // システムメッセージ用のチャンネル
// const channel = member.guild.channels.cache.get('チャンネルID'); // 特定のチャンネル
if (channel) {
channel.send(message);
console.log(`メッセージが出力されました!`);
console.log(message);
}
});

Expand Down

0 comments on commit 68a193d

Please sign in to comment.