async def unblock(self, ctx, user: discord.Member):
     if my_channel.is_nedoko(ctx.channel):
         if ctx.channel.permissions_for(ctx.author).manage_channels == True:
             await ctx.channel.set_permissions(user, read_messages=None)
             await ctx.send(f"{ctx.author.mention}->``{user}``から``{ctx.channel}``を見えるようにしました!")
         else:
             await ctx.send(f"{ctx.author.mention}->あなたは、``{ctx.channel}``の所有者ではありません!")
     else:
         return
 async def setname(self, ctx: commands.Context, *, after_name: str):
     if my_channel.is_nedoko(ctx.channel):
         data = {}
         for perm in ctx.channel.permissions_for(ctx.author):
             data[perm[0]] = perm[1]
         if data['manage_channels'] == True:
             await ctx.channel.edit(name=after_name)
             await ctx.send(f"{ctx.author.mention}->このチャンネル名を``{after_name}``に変更しました!")
         else:
             await ctx.message.delete()
     else:
         await ctx.send(f"{ctx.author.mention}->この機能は、寝床内で使用できます!")
 async def settopic(self, ctx, *, topic):
     if my_channel.is_nedoko(ctx.channel):
         data = {}
         for perm in ctx.channel.permissions_for(ctx.author):
             data[perm[0]] = perm[1]
         if data['manage_channels'] == True:
             if topic == "None":
                 await ctx.channel.edit(topic=None)
                 await ctx.send(f"{ctx.author.mention}->このチャンネルのチャンネルトピックを削除しました!")
             else:
                 await ctx.channel.edit(topic=topic)
                 await ctx.send(f"{ctx.author.mention}->このチャンネルのチャンネルトピックを以下の文章に変更しました!\n```\n{topic}\n```")
         else:
             await ctx.message.delete()
     else:
         await ctx.send(f"{ctx.author.mention}->この機能は、寝床内で使用できます!")
 async def setinv(self, ctx: commands.Context, check: str):
     if my_channel.is_nedoko(ctx.channel):
         data = {}
         for perm in ctx.channel.permissions_for(ctx.author):
             data[perm[0]] = perm[1]
         if data['manage_channels'] == True:
             role = ctx.guild.get_role(570641230661156870)
             if check == "True":
                 await ctx.channel.set_permissions(role, read_messages=False)
                 await ctx.send(f"{ctx.author.mention}->このチャンネルを``ロック``しました!このチャンネルは現在、信頼人とスタッフにのみ見えています!")
             elif check == "False":
                 await ctx.channel.set_permissions(role, read_messages=None)
                 await ctx.send(f"{ctx.author.mention}->このチャンネルを``アンロック``しました!このチャンネルは現在、全ての個人チャンネル利用者に見えています!")
             else:
                 await ctx.send(f"{ctx.author.mention}->チャンネルをロックするためには、``s/setlock <True/False>`` と入力して下さい!\n※``True``が``有効化``、``False``が``無効化``になります。")
         else:
             await ctx.message.delete()
     else:
         await ctx.send(f"{ctx.author.mention}->この機能は、寝床内で使用できます!")
    async def settrusted(self, ctx, check, member: discord.Member):
        if my_channel.is_nedoko(ctx.channel):
            if check in ["add", "+", "a"]:
                data = {}
                for perm in ctx.channel.permissions_for(ctx.author):
                    data[perm[0]] = perm[1]
                if data["manage_channels"] == True:
                    wait_message = await ctx.send(f"{ctx.author.mention}->", embed=discord.Embed(title=f"⚠{member}を#{ctx.channel}の信頼人に追加しようとしています!⚠", description=f"信頼人を付与すると、``{member}``は以下のことが可能になります:\n```○メッセージの管理(ピン留めや削除)\n○このホームが非公開にされている場合の閲覧可能権限```\n**__信頼できる人、もしくはサブアカウントなどに付与するようにして下さい!__**\n\n``{member}``に信頼人を付与する場合は✅を、付与しない場合は❌を押して下さい。"))
                    for emoji in ["✅", "❌"]:
                        await wait_message.add_reaction(emoji)

                    def check(reaction, user):
                        return user == ctx.author and str(reaction.emoji) in ['✅', '❌']
                    try:
                        reaction, user = await self.bot.wait_for('reaction_add', timeout=30.0, check=check)
                    except asyncio.TimeoutError:
                        await wait_message.clear_reactions()
                        await wait_message.edit(content=f"{ctx.author.mention}->指定した時間までに反応がなかったため、付与を行いませんでした!", embed=None)
                    else:
                        if reaction.emoji == "✅":
                            await ctx.channel.set_permissions(member, manage_messages=True, read_messages=True)
                            await wait_message.clear_reactions()
                            try:
                                await member.send(f"あなたは、``{ctx.author}``から{ctx.channel.mention}の信頼人に追加されました!")
                            except:
                                pass
                            await wait_message.edit(content=f"{ctx.author.mention}->``{member}``を信頼人に追加しました!", embed=None)
                        else:
                            await wait_message.clear_reactions()
                            await wait_message.edit(content=f"{member}を信頼人に追加することをキャンセルしました!", embed=None)
            elif check in ["del", "delete", "remove", "d", "r", "-"]:
                data = {}
                for perm in ctx.channel.permissions_for(ctx.author):
                    data[perm[0]] = perm[1]
                if data["manage_channels"] == True:
                    trust = {}
                    for perm in ctx.channel.permissions_for(member):
                        trust[perm[0]] = perm[1]
                    if trust["manage_messages"] == False:
                        await ctx.send(f"{ctx.author.mention}->``{member}``は信頼人ではありません!")
                        return
                    else:
                        wait_message = await ctx.send(f"{ctx.author.mention}->", embed=discord.Embed(title=f"⚠{member}を#{ctx.channel}の信頼人から削除しようとしています!⚠", description=f"``{member}``から信頼人を削除する場合は✅を、削除しない場合は❌を押して下さい。"))
                        for emoji in ["✅", "❌"]:
                            await wait_message.add_reaction(emoji)

                        def check(reaction, user):
                            return user == ctx.author and str(reaction.emoji) in ['✅', '❌']
                        try:
                            reaction, user = await self.bot.wait_for('reaction_add', timeout=30.0, check=check)
                        except asyncio.TimeoutError:
                            await wait_message.clear_reactions()
                            await wait_message.edit(content=f"{ctx.author.mention}->指定した時間までに反応がなかったため、削除を行いませんでした!", embed=None)
                        else:
                            if reaction.emoji == "✅":
                                await ctx.channel.set_permissions(member, manage_messages=None, read_messages=None)
                                await wait_message.clear_reactions()
                                await wait_message.edit(content=f"{ctx.author.mention}->``{member}``を信頼人から削除しました!", embed=None)
                            else:
                                await wait_message.clear_reactions()
                                await wait_message.edit(content=f"{member}を信頼人から削除することをキャンセルしました!", embed=None)
                else:
                    await ctx.message.delete()
            else:
                await ctx.send(f"{ctx.author.mention}->使用方法は``s/settrusted <add/del> <追加したいユーザー>``です!\n※``add``は追加を、``del``は削除を示しています。")
        else:
            await ctx.send(f"{ctx.author.mention}->この機能は、寝床内で使用できます!")
 async def setunlock(self, ctx):
     if my_channel.is_nedoko(ctx.channel):
         if ctx.channel.permissions_for(ctx.author).manage_channels is True:
             role = ctx.guild.get_role(570641230661156870)
             await ctx.channel.set_permissions(role, send_messages=None)
             await ctx.send(f"{ctx.author.mention}->他のユーザーがこの寝床に`書き込みできる`ようにしました!")
    async def on_message(self, message: discord.Message):
        if message.author.bot or not message.content == "メニュー" or not my_channel.is_nedoko(
                message.channel):
            return

        if not my_channel.check_owner(
                message.author, message.channel) and not (
                    await YonosumiStaff.is_admin(self.bot, message)):
            return

        select_dict = {
            "書き込み権限設定": "一般メンバーの書き込みの有無の設定ができます。",
            "寝床表示設定": "一般メンバーから寝床を見えるようにするかどうかの設定ができます。",
            "リアクション追加権限設定":
            "一般メンバーがリアクションを追加できるかの設定ができます(ただし、既存のリアクションを押すことはこの権限に関わらず可能です)",
            "スレッド関連設定": "スレッドの作成/削除/アーカイブなどが行なえます。",
            "信頼人関連設定": "信頼人の追加/削除が行なえます。",
            "ブロック設定":
            "寝床を見えなくしたいユーザーの追加/削除が行なえます。(この設定中は自動的に一般メンバーから寝床が見えなくなります。)",
            "寝床所有者移動設定": "寝床の所有者を移動できます。",
            "終了": "メニューを閉じます。"
        }
        flag = False
        base_message = None
        await message.delete()
        ctx = await self.bot.get_context(message)
        base_role = message.guild.get_role(570641230661156870)
        while flag is False:
            UI = MainControllerUI(message, select_dict)
            embed = YonosumiEmbed(
                title=f"メニュー", description="ドロップダウンメニューから実行したいメニューを選択してください。")
            embed.add_field(name="現在の設定",
                            value=NedokoPerm().get_my_channel_data(
                                channel=message.channel, base_role=base_role))
            if base_message is None:
                base_message = await message.channel.send(
                    content=f"{message.author.mention}->",
                    embed=embed,
                    view=UI)

            else:
                await base_message.edit(content=f"{message.author.mention}->",
                                        embed=embed,
                                        view=UI)
            await UI.wait()

            ui_interaction = UI.controller.interaction
            if ui_interaction is None:
                return await base_message.delete()

            ui_value = UI.controller.values[0]
            print(UI.controller.values)

            if ui_value in ["書き込み権限設定", "寝床表示設定", "リアクション追加権限設定"]:
                question_view = oxQuestion()
                await base_message.edit(
                    content=
                    f"{message.author.mention}->`{ui_value}`を有効にするか無効にするかを30秒以内にボタンで選択してください。",
                    view=question_view)
                await question_view.wait()

                ox_answer = question_view.answer
                if ox_answer is None:
                    try:
                        await base_message.edit(
                            content=
                            f"{message.author.mention}->30秒以内に応答しなかったため設定を終了しました。"
                        )
                        return await DeleteMessage().add_trash_emoji(
                            base_message, self.bot)
                    except:
                        return
                ox_answer_word = question_view.answer_word

            if ui_value == "書き込み権限設定":
                await message.channel.set_permissions(target=base_role,
                                                      send_messages=ox_answer)
                await self.success_message(message=base_message,
                                           value=ui_value,
                                           answer_word=ox_answer_word)
                await sleep(5)
                continue

            elif ui_value == "寝床表示設定":
                await message.channel.set_permissions(target=base_role,
                                                      read_messages=ox_answer)
                await self.success_message(message=base_message,
                                           value=ui_value,
                                           answer_word=ox_answer_word)
                await sleep(5)
                continue

            elif ui_value == "リアクション追加権限設定":
                await message.channel.set_permissions(target=base_role,
                                                      add_reactions=ox_answer)
                await self.success_message(message=base_message,
                                           value=ui_value,
                                           answer_word=ox_answer_word)
                await sleep(5)
                continue

            elif ui_value == "スレッド関連設定":
                await base_message.edit(
                    content=
                    f"{message.author.mention}->この機能は開発中です!\n5秒後にメインメニューに戻ります。",
                    view=None,
                    embed=None)
                await sleep(5)
                continue

            elif ui_value == "信頼人関連設定":
                await base_message.edit(
                    content=
                    f"{message.author.mention}->この機能は開発中です!\n5秒後にメインメニューに戻ります。",
                    view=None,
                    embed=None)
                await sleep(5)
                continue
                pass

            elif ui_value == "ブロック設定":
                await message.channel.set_permissions(base_role,
                                                      read_messages=False)
                blocks = NedokoPerm.get_block_data(message.channel)
                view_flag = None
                view = AddOrRemoveQuestion()

                if blocks:
                    description = ""
                    for i in blocks:
                        description += f"{i.mention}(`{i.id}`)\n"
                    block_embed = YonosumiEmbed(title=f"現在ブロック中のユーザー",
                                                description=description)
                    view_flag = True
                else:
                    block_embed = YonosumiEmbed(title=f"現在ブロック中のユーザー",
                                                description="現在誰もブロックしていません。")
                    view_flag = None

                if view_flag:
                    await base_message.edit(
                        content=
                        f"{message.author.mention}->ブロックするユーザーを追加するか削除するかをボタンで選択してください。",
                        embed=block_embed,
                        view=view)

                    await view.wait()

                    if view.answer is None:
                        await base_message.edit(
                            content=
                            f"{message.author.mention}->30秒以内に応答しなかったため設定を終了しました。",
                            embed=None,
                            view=None)
                        await message.channel.set_permissions(
                            base_role, read_messages=None)
                        return await DeleteMessage().add_trash_emoji(
                            base_message, self.bot)

                    answer = view.answer

                else:
                    answer = True

                def check(m):
                    return m.channel == message.channel and m.author == message.author

                if answer is True:  # 追加
                    await base_message.edit(
                        content=
                        f"{message.author.mention}->ブロックしたいユーザーのユーザー名もしくはIDを入力してください。\n入力を中断したい場合は`戻る`と入力してください。",
                        embed=block_embed)
                    user = None
                    while user is None:
                        try:
                            answer: discord.Message = await self.bot.wait_for(
                                "message", check=check, timeout=30.0)
                            await answer.delete()
                        except TimeoutError:
                            await base_message.edit(
                                content=
                                f"{message.author.mention}->30秒以内に反応がなかったためウィザードを終了しました。",
                                view=None,
                                embed=None)
                            await message.channel.set_permissions(
                                base_role, read_messages=None)
                            return

                        if answer.content in ["戻る"]:
                            await message.channel.set_permissions(
                                base_role, read_messages=None)
                            break

                        try:
                            user = await commands.MemberConverter().convert(
                                ctx, answer.content)
                            if user.bot:
                                await base_message.edit(
                                    content=
                                    f"{message.author.mention}->Botをブロックすることはできません!\n戻りたい場合は`戻る`と入力してください!"
                                )
                                user = None

                            elif user == message.author:
                                await base_message.edit(
                                    content=
                                    f"{message.author.mention}->自分自身をブロックすることはできません!\n戻りたい場合は`戻る`と入力してください!"
                                )
                                user = None

                        except Exception as e:
                            print(e)
                            await base_message.edit(
                                content=
                                f"{message.author.mention}->メンバーを取得できませんでした!ユーザー名もしくはユーザーIDで指定してください!"
                            )

                    if answer.content in ["戻る"]:
                        continue

                    await message.channel.set_permissions(user,
                                                          read_messages=False)
                    await message.channel.set_permissions(base_role,
                                                          read_messages=None)
                    await view.interaction.followup.send(
                        content=
                        f"{message.author.mention}->{user.mention}をブロックしました。",
                        ephemeral=True)
                    continue

                else:  # 削除
                    await base_message.edit(
                        content=
                        f"{message.author.mention}->ブロックを解除したいユーザーのユーザー名もしくはIDを入力してください。\n入力を中断したい場合は`戻る`と入力してください。\nまた、ブロックしていないユーザーを選択することはできません。",
                    )
                    user = None
                    while user is None:
                        try:
                            answer: discord.Message = await self.bot.wait_for(
                                "message", check=check, timeout=30.0)
                            await answer.delete()
                        except TimeoutError:
                            await base_message.edit(
                                content=
                                f"{message.author.mention}->30秒以内に反応がなかったためウィザードを終了しました。",
                                view=None,
                                embed=None)
                            await message.channel.set_permissions(
                                base_role, read_messages=None)
                            return

                        if answer.content in ["戻る"]:
                            await message.channel.set_permissions(
                                base_role, read_messages=None)
                            break

                        try:
                            user = await commands.MemberConverter().convert(
                                ctx, answer.content)
                            if not user in blocks:
                                await base_message.edit(
                                    content=
                                    f"{message.author.mention}->{user.mention}はブロックしていないため選択できません。"
                                )
                                user = None

                        except Exception as e:
                            await base_message.edit(
                                content=
                                f"{message.author.mention}->メンバーを取得できませんでした!ユーザー名もしくはユーザーIDで指定してください!"
                            )
                    await message.channel.set_permissions(user,
                                                          read_messages=None)
                    await message.channel.set_permissions(base_role,
                                                          read_messages=None)
                    await view.interaction.followup.send(
                        content=
                        f"{message.author.mention}->{user.mention}のブロックを解除しました。",
                        ephemeral=True)
                    continue

            elif ui_value == "寝床所有者移動設定":
                await base_message.edit(
                    content=
                    f"{message.author.mention}->この機能は開発中です!\n5秒後にメインメニューに戻ります。",
                    view=None,
                    embed=None)
                await sleep(5)

                def check(m):
                    return m.channel == message.channel and m.author == message.author

                await base_message.edit(
                    content=
                    f"{message.author.mention}->寝床の所有権を移動したいユーザーの名前もしくはIDを入力してください。\n戻る場合は`戻る`と入力してください。"
                )
                member = None
                while member is None:

                    try:
                        answer: discord.Message = await self.bot.wait_for(
                            'message', check=check, timeout=30.0)
                        if answer.content in ["戻る"]:
                            break

                    except TimeoutError:
                        return await base_message.edit(
                            content=
                            f"{message.author.mention}->30秒以内に応答しなかったため、ウィザードを終了しました。"
                        )

                    try:
                        member = await commands.MemberConverter().convert(
                            ctx, answer.content)

                    except:
                        await base_message.edit(
                            content=
                            f"{message.author.mention}->メンバーを取得できませんでした!ユーザー名もしくはIDで指定してください。"
                        )

                if answer.content in ["戻る"]:
                    continue

                yes_or_no_view = YesOrNoQuestion()
                await base_message.edit(
                    content=
                    f"{message.author.mention}->{member.mention}へ{message.channel.mention}の所有権を移動しますか?\n※はいを押すと{member.mention}にDM(DMが送信できなかった場合はこのチャンネルに)移動を承諾するかどうかの確認メッセージが送信されます。",
                    view=yes_or_no_view)
                await yes_or_no_view.wait()

                if yes_or_no_view.answer is None:
                    return await base_message.edit(
                        content=
                        f"{message.author.mention}->30秒以内に解答しなかったためウィザードを終了します。"
                    )

                elif yes_or_no_view.answer is False:
                    await base_message.edit(
                        content=
                        f"{message.author.mention}->所有権移動設定を終了しました。5秒後にメインメニューに戻ります。",
                        embed=None,
                        view=None)
                    await sleep(5)
                    continue

                else:
                    embed = YonosumiEmbed(title=f"チャンネル概要")
                    embed.add_field(name="チャンネル名",
                                    value=message.channel.mention,
                                    inline=False)
                    embed.add_field(name="チャンネルID",
                                    value=str(message.channel.id),
                                    inline=False)
                    embed.add_field(name="申請者",
                                    value=message.author.mention,
                                    inline=False)

                    try:
                        await member.send(
                            content=
                            f"{member.mention}->{message.author.mention}から{message.channel.mention}の所有権移動の申請がありました。\n承諾する場合は`承諾`、拒否する場合は`拒否`のボタンを入力してください。",
                            embed=embed,
                            view=AllowOrDenyQuestion())

                    except:
                        await message.channel.send(
                            content=
                            f"{member.mention}->{message.author.mention}から{message.channel.mention}の所有権移動の申請がありました。\n承諾する場合は`承諾`、拒否する場合は`拒否`のボタンを入力してください。",
                            embed=embed,
                            view=AllowOrDenyQuestion())

            elif ui_value == "終了":
                return await base_message.delete()