generated from DiscordBotPortalJP/discordpy-startup
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc15859
commit 218e03c
Showing
11 changed files
with
87 additions
and
51 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from dotenv import load_dotenv | ||
from os import getenv | ||
|
||
load_dotenv() | ||
|
||
TOKEN = getenv('DISCORD_BOT_TOKEN') |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import traceback | ||
from discord.ext import commands | ||
from utils.errors import PermissionNotFound, NotGuildChannel, NotDMChannel | ||
|
||
|
||
class HandleErrorCog(commands.Cog): | ||
def __init__(self, bot: commands.Bot): | ||
self.bot = bot | ||
|
||
@commands.Cog.listener() | ||
async def on_command_error(ctx, error: commands.CommandError): | ||
"""エラーハンドリング""" | ||
|
||
if isinstance(error, commands.CheckFailure): | ||
return | ||
|
||
if isinstance(error, PermissionNotFound): | ||
await ctx.send('コマンドを実行する権限がありません') | ||
return | ||
|
||
if isinstance(error, NotGuildChannel): | ||
await ctx.send('サーバー内でのみ実行できるコマンドです') | ||
return | ||
|
||
if isinstance(error, NotDMChannel): | ||
await ctx.send('DM内でのみ実行できるコマンドです') | ||
return | ||
|
||
orig_error = getattr(error, "original", error) | ||
error_msg = ''.join(traceback.TracebackException.from_exception(orig_error).format()) | ||
error_msg = "```py\n" + error_msg + "\n```" | ||
await ctx.send(error_msg) | ||
|
||
|
||
async def setup(bot: commands.Bot) -> None: | ||
await bot.add_cog(HandleErrorCog(bot)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,34 @@ | ||
import os | ||
import traceback | ||
import discord | ||
from discord.ext import commands | ||
from application.game import Game | ||
from application.errors import PermissionNotFound, NotGuildChannel, NotDMChannel | ||
|
||
bot = commands.Bot(command_prefix='/') | ||
bot.game = Game() | ||
from constants.discord import TOKEN | ||
|
||
extensions = [ | ||
'cogs.status', | ||
'cogs.players', | ||
'cogs.vote', | ||
'handle_error', | ||
'players', | ||
'status', | ||
'vote', | ||
] | ||
for extension in extensions: | ||
bot.load_extension(extension) | ||
|
||
|
||
@bot.event | ||
async def on_command_error(ctx, error): | ||
"""エラーハンドリング""" | ||
|
||
if isinstance(error, commands.CheckFailure): | ||
return | ||
|
||
if isinstance(error, PermissionNotFound): | ||
await ctx.send('コマンドを実行する権限がありません') | ||
return | ||
class WerewolfBot(commands.Bot): | ||
def __init__(self): | ||
super().__init__( | ||
command_prefix=commands.when_mentioned_or('$'), | ||
intents=discord.Intents.all(), | ||
) | ||
|
||
if isinstance(error, NotGuildChannel): | ||
await ctx.send('サーバー内でのみ実行できるコマンドです') | ||
return | ||
async def setup_hook(self): | ||
for extension in extensions: | ||
await self.load_extension(f'extensions.{extension}') | ||
# await self.tree.sync() | ||
|
||
if isinstance(error, NotDMChannel): | ||
await ctx.send('DM内でのみ実行できるコマンドです') | ||
return | ||
|
||
orig_error = getattr(error, "original", error) | ||
error_msg = ''.join(traceback.TracebackException.from_exception(orig_error).format()) | ||
error_msg = "```py\n" + error_msg + "\n```" | ||
await ctx.send(error_msg) | ||
def main(): | ||
bot = WerewolfBot() | ||
bot.game = Game() | ||
bot.run(TOKEN) | ||
|
||
|
||
bot.run(os.environ['DISCORD_BOT_WEREWOLF_TOKEN']) | ||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
discord.py[voice]>=2.3.1 | ||
dotenv |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import discord | ||
|
||
class PermissionNotFound(discord.DiscordException): | ||
pass | ||
|
||
|
||
class NotGuildChannel(discord.DiscordException): | ||
pass | ||
|
||
|
||
class NotDMChannel(discord.DiscordException): | ||
pass |