Skip to content

Commit

Permalink
feat: 特定サーバでのコマンド実行に制限する処理を追加 (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
book000 authored Aug 27, 2023
1 parent 6ba8b13 commit dafc11e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ConfigFramework } from '@book000/node-utils'
export interface ConfigInterface {
discord: {
token: string
guildId?: string
channel?: {
greeting?: string
}
Expand Down
14 changes: 14 additions & 0 deletions src/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,27 @@ export class Discord {

async onMessageCreate(message: Message) {
const logger = Logger.configure('Discord.onMessageCreate')
// Botのメッセージは無視
if (message.author.bot) {
return
}

// guildIdが設定されている場合、そのサーバ以外のメッセージは無視
const onlyGuildId = this.config.get('discord').guildId
if (onlyGuildId && message.guild?.id !== onlyGuildId) {
return
}

// 対応するコマンドを探す
const command = Discord.commands.find((command) =>
message.content.startsWith(`/${command.name}`)
)
if (!command) {
// コマンドが見つからない場合は無視
return
}

// コマンドの実行権限を確認
if (command.permissions) {
const member = message.member
if (!member) {
Expand Down

0 comments on commit dafc11e

Please sign in to comment.