Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #3 from Huyu2239/add_slash_help
Browse files Browse the repository at this point in the history
Add slash help
  • Loading branch information
Huyu2239 authored Apr 10, 2021
2 parents f8544d6 + ded9899 commit edc9b98
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
97 changes: 97 additions & 0 deletions cogs/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
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())
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)
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):
bot.add_cog(Help(bot))
3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import discord
from discord.ext import commands
from discord_slash import SlashCommand

from dotenv import load_dotenv

load_dotenv()
Expand Down Expand Up @@ -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"):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
discord.py[voice]
discord-py-slash-command
python-dotenv

0 comments on commit edc9b98

Please sign in to comment.