From ca408859b2a1191f0e7fc885c1c230edbb7977dc Mon Sep 17 00:00:00 2001 From: Huyu2239 Date: Sat, 10 Apr 2021 18:09:41 +0900 Subject: [PATCH 1/2] add_slash_help --- cogs/help.py | 24 ++++++++++++++++++++++++ main.py | 3 +++ requirements.txt | 1 + 3 files changed, 28 insertions(+) create mode 100644 cogs/help.py diff --git a/cogs/help.py b/cogs/help.py new file mode 100644 index 0000000..5e59064 --- /dev/null +++ b/cogs/help.py @@ -0,0 +1,24 @@ +# import discord +from discord.ext import commands # , tasks +from discord_slash import SlashContext, cog_ext # SlashCommand +# from discord_slash.utils import manage_commands + +import asyncio + + +class Help(commands.Cog): + def __init__(self, bot): + self.bot = bot + asyncio.create_task(self.bot.slash.sync_all_commands()) + + def cog_unload(self): + self.bot.slash.remove_cog_commands(self) + + @cog_ext.cog_slash(name='help', description='このBotのHelpを返します。', guild_ids=[829431106263580703]) + async def slash_say(self, ctx: SlashContext): + # await ctx.respond(eat=True) + await ctx.send('help') + + +def setup(bot): + bot.add_cog(Help(bot)) diff --git a/main.py b/main.py index 1e7875a..6f76fd3 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,8 @@ import discord from discord.ext import commands +from discord_slash import SlashCommand + from dotenv import load_dotenv load_dotenv() @@ -30,6 +32,7 @@ def __init__(self, command_prefix, **options): self.guild_open = json.load(f) with open(f'{self.data_directory}embed_type.json') as f: self.emnbed_type = json.load(f) + self.slash_client = SlashCommand(self, sync_commands=True) async def on_ready(self): for cog in os.listdir("./cogs"): diff --git a/requirements.txt b/requirements.txt index 60c63bb..69ea1ae 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ discord.py[voice] +discord-py-slash-command python-dotenv \ No newline at end of file From ded98990d0d4bb2d4dd8857177959b927adffdb9 Mon Sep 17 00:00:00 2001 From: Huyu2239 Date: Sat, 10 Apr 2021 22:02:28 +0900 Subject: [PATCH 2/2] activate_slash_help --- cogs/help.py | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/cogs/help.py b/cogs/help.py index 5e59064..0a2be4e 100644 --- a/cogs/help.py +++ b/cogs/help.py @@ -1,4 +1,4 @@ -# import discord +import discord from discord.ext import commands # , tasks from discord_slash import SlashContext, cog_ext # SlashCommand # from discord_slash.utils import manage_commands @@ -10,14 +10,87 @@ class Help(commands.Cog): def __init__(self, bot): self.bot = bot asyncio.create_task(self.bot.slash.sync_all_commands()) + self.help_em = self.compose_help() def cog_unload(self): self.bot.slash.remove_cog_commands(self) + def compose_help(self): + help_em = [ + ( + discord.Embed( + title="概要", + description="Discordのメッセージリンクを展開するBotです。", + color=discord.Colour.blue() + ) + ), + ( + discord.Embed( + title="コマンド一覧", + color=discord.Colour.blue() + ) + ) + ] + help_em[0].add_field( + name='URL一覧', + value="[サポートサーバー](https://discord.gg/zNBeuM8Epd)\n[導入リンク](https://discord.com/api/oauth2/authorize?client_id=827863670507438130&permissions=85056&scope=bot%20applications.commands)" + ) + help_em[0].add_field( + name='動作サーバー数', + value=f'{len(self.bot.guilds)}guilds' + ) + help_em[0].add_field( + name='動作環境', + value='[Tera-server](https://tera-server.com/)' + ) + help_em[0].add_field( + name='総ユーザー数', + value=f'{len(set(self.bot.get_all_members()))}users' + ) + help_em[1].add_field( + name='`/help`', + value='このメッセージを送信します' + ) + help_em[1].add_field( + name='`/embed_type`', + value='展開メッセージの装飾を変更できます\nデフォルトは1です' + ) + help_em[1].add_field( + name='`/public`', + value='サーバー内のメッセージのリンクが他のサーバーに送信された場合の展開の**ON・OFF**を切り替えます\n送信元の設定がOFFの場合はリンク先のサーバーの設定がONの場合でも展開**されません**', + inline=False + ) + return help_em + @cog_ext.cog_slash(name='help', description='このBotのHelpを返します。', guild_ids=[829431106263580703]) async def slash_say(self, ctx: SlashContext): # await ctx.respond(eat=True) - await ctx.send('help') + page = 0 + help_msg = await ctx.send(embed=self.help_em[page]) + emoji = '➡' + await help_msg.add_reaction(emoji) + await help_msg.add_reaction(emoji) + while True: + def reaction_check(reaction, user): + if reaction.message.id == help_msg.id \ + and user == ctx.author: + return reaction, user + + try: + reaction, user = await self.bot.wait_for( + "reaction_add", timeout=60.0, check=reaction_check) + emoji = str(reaction.emoji) + except asyncio.TimeoutError: + await help_msg.remove_reaction(emoji, self.bot.user) + return + # await help_msg.remove_reaction(emoji, user) + if page == len(self.em): + # 最大の時は最初に + page = 0 + else: + # その他は一つ上がる + page += 1 + await help_msg.edit(embed=self.em[page]) def setup(bot):