Skip to content

Commit e8d4700

Browse files
committed
feat: ボイスチャンネル参加/退出コマンドにレートリミットを追加し、エラーハンドラを実装
1 parent a48d37f commit e8d4700

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

cogs/voice/basic.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ async def is_banned(self, user_id: int) -> bool:
169169
return user_id in self.banlist
170170

171171
@app_commands.command(name="join", description="ボイスチャンネルに参加")
172+
@commands.cooldown(1, 10, commands.BucketType.user) # 追加: 10秒に1回
172173
async def join(self, interaction: discord.Interaction):
173174
if await self.is_banned(interaction.user.id):
174175
await interaction.response.send_message("このコマンドを実行する権限がありません。", ephemeral=True)
@@ -269,6 +270,7 @@ async def play_connection_message():
269270
await interaction.response.send_message(embed=embed, ephemeral=True)
270271

271272
@app_commands.command(name="leave", description="ボイスチャンネルから退出")
273+
@commands.cooldown(1, 10, commands.BucketType.user) # 追加: 10秒に1回
272274
async def leave(self, interaction: discord.Interaction):
273275
if await self.is_banned(interaction.user.id):
274276
await interaction.response.send_message("このコマンドを実行する権限がありません。", ephemeral=True)
@@ -1024,5 +1026,25 @@ async def sync_vcstate_once(self):
10241026
gid, vc.channel.id, tts_channel_id
10251027
)
10261028

1029+
async def cog_app_command_error(self, interaction: discord.Interaction, error):
1030+
"""アプリコマンドのエラーハンドラ(レートリミット対応)"""
1031+
if isinstance(error, commands.CommandOnCooldown):
1032+
await interaction.response.send_message(
1033+
f"このコマンドはレートリミット中です。あと{error.retry_after:.1f}秒後に再度お試しください。",
1034+
ephemeral=True
1035+
)
1036+
else:
1037+
raise error
1038+
1039+
async def cog_command_error(self, ctx, error):
1040+
"""通常コマンドのエラーハンドラ(レートリミット対応)"""
1041+
if isinstance(error, commands.CommandOnCooldown):
1042+
await ctx.send(
1043+
f"このコマンドはレートリミット中です。あと{error.retry_after:.1f}秒後に再度お試しください。",
1044+
delete_after=10
1045+
)
1046+
else:
1047+
raise error
1048+
10271049
async def setup(bot):
10281050
await bot.add_cog(VoiceReadCog(bot))

0 commit comments

Comments
 (0)