コード例 #1
0
    async def on_message(self, message):
        if message.content.startswith("dc"):
            # 入力された内容を受け取る
            say = message.content

            # [rtdc ]部分を消し、AdBのdで区切ってリスト化する
            order = say.strip('dc ')
            cnt, mx = list(map(int, order.split('d')))  # さいころの個数と面数
            dice = diceroll(cnt, mx)  # 和を計算する関数(後述)
            await message.channel.send(dice[cnt])
            del dice[cnt]

            # さいころの目の総和の内訳を表示する
            await message.channel.send(dice)
コード例 #2
0
async def on_message(message):
    if message.author.bot:
        return
#ねこ移植
    if message.content.startswith("/neko"):
        MeowText = neko()
        await message.channel.send(MeowText)
        #await message.channel.send('にゃーん')

    if message.content.startswith("/dice"):
        # 入力された内容を受け取る
        say = message.content

        # [!dice ]部分を消し、AdBのdで区切ってリスト化する
        order = say.strip('/dice ')
        cnt, mx = list(map(int, order.split('d')))  # さいころの個数と面数
        dice = diceroll(cnt, mx)  # 和を計算する関数(後述)
        await message.channel.send(dice[cnt])
        del dice[cnt]

        # さいころの目の総和の内訳を表示する
        await message.channel.send(dice)
コード例 #3
0
async def on_message(message):

    url_re = r"https://discordapp.com/channels/(\d{18})/(\d{18})/(\d{18})"
    url_list = re.findall(url_re, message.content)

    for url in url_list:
        guild_id, channel_id, message_id = url
        channel = client.get_channel(int(channel_id))

        if channel is not None:
            got_message = await channel.fetch_message(message_id)

            if got_message is not None:
                await message.channel.send(embed=open_message(got_message))

    if message.author.id == 302050872383242240:
        if "表示順をアップ" in message.embeds[0].description:
            msg = await message.channel.send("Bumpを確認しました。2時間後に通知します。")
            await asyncio.sleep(10)
            m = 0
            while m < 7201:
                b = 7200
                s = b - m
                await msg.edit(content=f"あと{s}秒後にBumpできます。")
                await asyncio.sleep(1)
                m += 1
            await msg.edit(content=f"Bump可能")

    if message.author.bot:  # ボットを弾く。
        return

    if client.user in message.mentions:  # 話しかけられたかの判定
        hensin = random.choice(
            ('よんだ?', 'なにー?', 'たべちゃうぞー!', 'がおー!', 'よろしくね', '!?'))
        reply = f'{message.author.mention} さん' + hensin + '```\n 私の機能が分からなかったら「ヘルプ」と打ってね☆```'  #返信メッセージの作成
        await message.channel.send(reply)  # 返信メッセージを送信

    if message.content.startswith("おはよ"):  #から始まるメッセージ
        #指定したチャンネルとメッセージを送ったチャンネルが同じIDなら実行
        if message.author.id == great_owner_id:
            await message.channel.send('おはようございます!マスターさん!今日も一日頑張って下さい!')
        if not message.author.id == great_owner_id:
            await message.channel.send(
                f"{message.author.mention} さん。おはようございます。")

    if message.content.startswith("おやす"):  #から始まるメッセージ
        #指定したチャンネルとメッセージを送ったチャンネルが同じIDなら実行
        if message.author.id == great_owner_id:
            await message.channel.send('おやすみなさい!マスターさん!今日も一日お疲れさまでした!')
        if not message.author.id == great_owner_id:
            await message.channel.send(f"{message.author.mention} さん。おやすみなさい。")

    if message.content == "ジャンケン":

        await message.channel.send("最初はグー、じゃんけん")

        def jankencheck(m):
            return m.content == "グー" or "チョキ" or "パー" and m.author == message.author

        try:
            reply = await client.wait_for("message",
                                          check=jankencheck,
                                          timeout=10.0)
        except asyncio.TimeoutError:
            await message.channel.send("後出しはいけませんよ!\nあなたの負け!")
        else:
            if reply.content == "チョキ":
                result = "グー"

            elif reply.content == "パー":
                result = "チョキ"

            elif reply.content == "グー":
                result = "パー"

            elif not reply.content == "グー" or reply.content == "チョキ" or reply.content == "パー":
                await message.channel.send("不適切な返事です。\nあなたの負け!")
                return

            await message.channel.send(result + "を出しました \nあなたの負け!")

    if message.content == "おみくじ":
        # Embedを使ったメッセージ送信 と ランダムで要素を選択
        embed = discord.Embed(
            title="おみくじ",
            description=f"{message.author.mention}さんの今日の運勢は!",
            color=0x2ECC69)
        embed.set_thumbnail(url=message.author.avatar_url)
        embed.add_field(name="[運勢] ",
                        value=random.choice(
                            ('大吉', '中吉', '小吉', '吉', '半吉', '末吉', '末小吉', '凶',
                             '小凶', '半凶', '末凶', '大凶')),
                        inline=False)
        await message.channel.send(embed=embed)

    #運勢
    if message.content == '運勢':
        prob = random.random()

        if prob < 0.3:
            await message.channel.send('凶です……外出を控えることをオススメします')

        elif prob < 0.65:
            await message.channel.send('吉です!何かいい事があるかもですね!')

        elif prob < 0.71:
            await message.channel.send('末吉……どれくらい運がいいんでしょうね?•́ω•̀)?')

        elif prob < 0.76:
            await message.channel.send('半吉は吉の半分、つまり運がいいのです!')

        elif prob < 0.80:
            await message.channel.send('小吉ですね!ちょっと優しくされるかも?')

        elif prob < 0.83:
            await message.channel.send('吉の中で1番当たっても微妙に感じられる……つまり末吉なのです( ´・ω・`)'
                                       )

        elif prob <= 1.0:
            await message.channel.send('おめでとうございます!大吉ですよ!(๑>∀<๑)♥')

    if message.content == '御神籤':
        await asyncio.sleep(0.1)
        prob = random.random()

        if prob < 0.02:  #大凶
            await message.channel.send(
                'https://cdn.discordapp.com/attachments/649413089778728970/655056313637666816/20191213233945.jpg'
            )

        elif prob < 0.10:  #凶
            await message.channel.send(
                'https://cdn.discordapp.com/attachments/649413089778728970/655055945659056134/20191213233816.jpg'
            )

        elif prob < 0.35:  #吉
            await message.channel.send(
                'https://cdn.discordapp.com/attachments/649413089778728970/655055610441891840/20191213233638.jpg'
            )

        elif prob < 0.55:  #半吉
            await message.channel.send(
                'https://cdn.discordapp.com/attachments/649413089778728970/655054936773754890/20191213233418.jpg'
            )

        elif prob < 0.75:  #小吉
            await message.channel.send(
                'https://cdn.discordapp.com/attachments/649413089778728970/655054736638345238/20191213233326.jpg'
            )

        elif prob < 0.95:  #末吉
            await message.channel.send(
                'https://cdn.discordapp.com/attachments/649413089778728970/655054481956012046/20191213233205.jpg'
            )

        elif prob <= 1.0:  #大吉
            await message.channel.send(
                'https://cdn.discordapp.com/attachments/649413089778728970/655051678499995651/20191213232052.jpg'
            )

    if message.content == 'ステータス':
        if message.author.guild_permissions.administrator or message.author.id == great_owner_id:
            embed = discord.Embed(title="この鯖のステータス", description="Embed式")
            embed.add_field(name="サーバー名",
                            value=f'{message.guild.name}',
                            inline=False)
            embed.add_field(name="現オーナー名",
                            value=f'{message.guild.owner}',
                            inline=False)
            guild = message.guild
            member_count = sum(1 for member in guild.members if not member.bot)
            bot_count = sum(1 for member in guild.members if member.bot)
            all_count = (member_count) + (bot_count)
            embed.add_field(name="総人数", value=f'{all_count}', inline=False)
            embed.add_field(name="ユーザ数", value=f'{member_count}', inline=False)
            embed.add_field(name="BOT数", value=f'{bot_count}', inline=False)
            embed.add_field(name="テキストチャンネル数",
                            value=f'{len(message.guild.text_channels)}個',
                            inline=False)
            embed.add_field(name="ボイスチャンネル数",
                            value=f'{len(message.guild.voice_channels)}個',
                            inline=False)
            embed.set_thumbnail(url=message.guild.icon_url)
            await message.channel.send(embed=embed)

        else:
            await message.channel.send(
                '貴方は管理者権限がありません。 \n You do not have admin roles !!')

        #年月日
    if message.content == '何日?':
        date = datetime.datetime.now()
        await message.channel.send(
            f'今日は{date.year}年{date.month}月{date.day}日です!')
    if message.content == '何時?':
        date = datetime.datetime.now()
        await message.channel.send(
            f'今は{date.hour}時{date.minute}分{date.second}秒だよ!')
    if message.content == '時計':
        weekdays = datetime.date.today().weekday()
        if weekdays == 0:
            weekday_name = "月曜日"
        elif weekdays == 1:
            weekday_name = "火曜日"
        elif weekdays == 2:
            weekday_name = "水曜日"
        elif weekdays == 3:
            weekday_name = "木曜日"
        elif weekdays == 4:
            weekday_name = "金曜日"
        elif weekdays == 5:
            weekday_name = "土曜日"
        elif weekdays == 6:
            weekday_name = "日曜日"
        else:
            weekday_name = "エラー"
        date = datetime.datetime.now()
        embed = discord.Embed(title="時計",
                              description="TimeZone(Japan)",
                              color=random.choice(
                                  (0, 0x1abc9c, 0x11806a, 0x2ecc71, 0x1f8b4c,
                                   0x3498db, 0x206694, 0x9b59b6, 0x71368a,
                                   0xe91e63, 0xad1457, 0xf1c40f, 0xc27c0e,
                                   0xe67e22, 0x95a5a6, 0x607d8b, 0x979c9f,
                                   0x546e7a, 0x7289da, 0x99aab5)))
        embed.add_field(
            name="日付",
            value=f'{date.year}年{date.month}月{date.day}日{weekday_name}',
            inline=False)
        embed.add_field(name="時間",
                        value=f'{date.hour}時{date.minute}分{date.second}秒',
                        inline=False)
        embed.set_thumbnail(
            url=
            "https://cdn.discordapp.com/attachments/688986679956340804/690461569854996490/180half_f.gif"
        )
        await message.channel.send(embed=embed)

    if message.content == 'nrestart':
        if message.author.id == great_owner_id:
            await message.channel.send('再起動します')
            await asyncio.sleep(0.5)
            await client.logout()
            os.execv(sys.executable,
                     [sys.executable,
                      os.path.join(sys.path[0], __file__)] + sys.argv[1:])
        if not message.author.id == great_owner_id:
            await message.channel.send('貴方にこのコマンドの使用権限はありません')

    if message.content == 'nclear':
        if message.author.id == great_owner_id:
            await message.channel.purge()
        if not message.author.id == great_owner_id:
            await message.channel.send('貴方にこのコマンドの使用権限はありません')

    if not message.author.id == 664880378481213473:
        prob = random.random()

        if prob < 0.02:
            if not message.content.startswith("スロット"):
                await message.add_reaction('💝')

    if message.content == "スロット":
        suroto = random.choice(
            ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))
        suroto1 = random.choice(
            ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))
        suroto2 = random.choice(
            ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))
        await asyncio.sleep(0.1)
        my_message = await message.channel.send('スロット結果がここに表示されます!')
        await asyncio.sleep(3)
        await my_message.edit(content='?|?|?')
        await asyncio.sleep(1)
        await my_message.edit(content=suroto + '|?|?')
        await asyncio.sleep(1)
        await my_message.edit(content=suroto + '|' + suroto1 + '|?')
        await asyncio.sleep(1)
        await my_message.edit(content=suroto + '|' + suroto1 + '|' + suroto2)
        if suroto == suroto1 == suroto2:
            await my_message.edit(content=suroto + '|' + suroto1 + '|' +
                                  suroto2 + '\n 結果:大当たり!!')
        elif suroto == suroto1 or suroto == suroto2 or suroto1 == suroto2:
            await my_message.edit(content=suroto + '|' + suroto1 + '|' +
                                  suroto2 + '\n 結果:リーチ!')
        else:
            await my_message.edit(content=suroto + '|' + suroto1 + '|' +
                                  suroto2 + '\n 結果:ハズレ')

    if message.content.startswith("!dc"):
        # 入力された内容を受け取る
        say = message.content

        # [!dc ]部分を消し、AdBのdで区切ってリスト化する
        order = say.strip('!dc ')
        cnt, mx = list(map(int, order.split('d')))  # さいころの個数と面数
        dice = diceroll(cnt, mx)  # 和を計算する関数(後述)
        await message.channel.send(dice[cnt])
        del dice[cnt]

        # さいころの目の総和の内訳を表示する
        await message.channel.send(dice)

    if message.content == 'coin sn1' or message.content == 'coin sn2':
        if message.author.id == great_owner_id:
            coin = random.choice(('●', '○'))
            if message.content == 'coin sn1':
                my_message = await message.channel.send('コイントスをします!')
                await asyncio.sleep(3)
                await my_message.edit(content='定義:○は表、●は裏')
                await asyncio.sleep(3)
                await my_message.edit(content='抽選中:○```定義:○は表、●は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中:●```定義:○は表、●は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中:○```定義:○は表、●は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中:●```定義:○は表、●は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中:○```定義:○は表、●は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中:●```定義:○は表、●は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中:○```定義:○は表、●は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中:●```定義:○は表、●は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中:○```定義:○は表、●は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中:●```定義:○は表、●は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中: ```定義:○は表、●は裏```')
                await asyncio.sleep(2)
                await my_message.edit(content=' 結果:' + coin +
                                      '```定義:○は表、●は裏 \n adid:sn1```')
                return
            elif message.content == 'coin sn2':
                my_message = await message.channel.send('コイントスをします!')
                await asyncio.sleep(3)
                await my_message.edit(content='定義:●は表、○は裏')
                await asyncio.sleep(3)
                await my_message.edit(content='抽選中:○```定義:●は表、○は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中:●```定義:●は表、○は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中:○```定義:●は表、○は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中:●```定義:●は表、○は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中:○```定義:●は表、○は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中:●```定義:●は表、○は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中:○```定義:●は表、○は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中:●```定義:●は表、○は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中:○```定義:●は表、○は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中:●```定義:●は表、○は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中: ```定義:●は表、○は裏```')
                await asyncio.sleep(2)
                await my_message.edit(content=' 結果:' + coin +
                                      '```定義:●は表、○は裏 \n adid:sn2```')
                return
        await message.channel.send('Error:You cannot use this command')
        return

    if message.content == 'coin':
        coin = random.choice(('●', '○'))
        coin1 = random.choice(('1', '2'))
        await asyncio.sleep(0.1)
        if coin1 == '1':
            my_message = await message.channel.send('コイントスをします!')
            await asyncio.sleep(3)
            await my_message.edit(content='定義:○は表、●は裏')
            await asyncio.sleep(3)
            await my_message.edit(content='抽選中:○```定義:○は表、●は裏```')
            await asyncio.sleep(0.5)
            await my_message.edit(content='抽選中:●```定義:○は表、●は裏```')
            await asyncio.sleep(0.5)
            await my_message.edit(content='抽選中:○```定義:○は表、●は裏```')
            await asyncio.sleep(0.5)
            await my_message.edit(content='抽選中:●```定義:○は表、●は裏```')
            await asyncio.sleep(0.5)
            await my_message.edit(content='抽選中:○```定義:○は表、●は裏```')
            await asyncio.sleep(0.5)
            await my_message.edit(content='抽選中:●```定義:○は表、●は裏```')
            await asyncio.sleep(0.5)
            await my_message.edit(content='抽選中:○```定義:○は表、●は裏```')
            await asyncio.sleep(0.5)
            await my_message.edit(content='抽選中:●```定義:○は表、●は裏```')
            await asyncio.sleep(0.5)
            await my_message.edit(content='抽選中:○```定義:○は表、●は裏```')
            await asyncio.sleep(0.5)
            await my_message.edit(content='抽選中:●```定義:○は表、●は裏```')
            await asyncio.sleep(0.5)
            await my_message.edit(content='抽選中: ```定義:○は表、●は裏```')
            await asyncio.sleep(2)
            await my_message.edit(content=' 結果:' + coin +
                                  '```定義:○は表、●は裏 \n adid:sn' + coin1 + '```')

            return
        elif coin1 == '2':
            my_message = await message.channel.send('コイントスをします!')
            await asyncio.sleep(3)
            await my_message.edit(content='定義:●は表、○は裏')
            await asyncio.sleep(3)
            await my_message.edit(content='抽選中:○```定義:●は表、○は裏```')
            await asyncio.sleep(0.5)
            await my_message.edit(content='抽選中:●```定義:●は表、○は裏```')
            await asyncio.sleep(0.5)
            await my_message.edit(content='抽選中:○```定義:●は表、○は裏```')
            await asyncio.sleep(0.5)
            await my_message.edit(content='抽選中:●```定義:●は表、○は裏```')
            await asyncio.sleep(0.5)
            await my_message.edit(content='抽選中:○```定義:●は表、○は裏```')
            await asyncio.sleep(0.5)
            await my_message.edit(content='抽選中:●```定義:●は表、○は裏```')
            await asyncio.sleep(0.5)
            await my_message.edit(content='抽選中:○```定義:●は表、○は裏```')
            await asyncio.sleep(0.5)
            await my_message.edit(content='抽選中:●```定義:●は表、○は裏```')
            await asyncio.sleep(0.5)
            await my_message.edit(content='抽選中:○```定義:●は表、○は裏```')
            await asyncio.sleep(0.5)
            await my_message.edit(content='抽選中:●```定義:●は表、○は裏```')
            await asyncio.sleep(0.5)
            await my_message.edit(content='抽選中: ```定義:●は表、○は裏```')
            await asyncio.sleep(2)
            await my_message.edit(content=' 結果:' + coin +
                                  '```定義:●は表、○は裏 \n adid:sn' + coin1 + '```')

            return
        await message.channel.send('Error')

    if message.content == 'ヘルプ':
        page_count = 0  #ヘルプの現在表示しているページ数
        page_content_list = [
            ">>> **ノアコマンド一覧(ページ1)**\n\n**何時?**:今の時間を教えてくれます!(何時何分何秒)\n**何日?**:何日か教えてくれます!(何月何日)\n\n➡絵文字を押すと次のページへ",
            ">>> **ノアコマンド一覧(ページ2)**\n\n**!dc XdY**:Y面のダイスをX回振ります!\n**coin**:コイントスを行います。\n**スロット**:あなたは大当たりを引けるのか!?\n\n➡絵文字で次のページ\n⬅絵文字で前のページ",
            ">>> **ノアコマンド一覧(ページ3)**\n\n**おみくじ**or**御神籤**:おみくじが引けます!\n**運勢**:貴方の運勢は!\n\n➡絵文字で次のページ\n⬅絵文字で前のページ",
            ">>> **ノアコマンド一覧(ページ4)**\n\n以下のコマンドは__管理者権限__が必要\n**ステータス**:この鯖のステータスです。\n\n➡絵文字で次のページ\n⬅絵文字で前のページ",
            ">>> **このBOT詳細情報(ページ5)**\n\nBOT名前:" + f"{client.user.name}" +
            "\nBOT ID:" + f"{client.user.id}" + "\nDiscord.pyバージョン:" +
            f"{discord.__version__}" + "\npythonバージョン:" + discord_py_ver +
            "\n開発バージョン:" + ksi_ver +
            "\n開発者:<@459936557432963103>\n\n⬅絵文字で前のページ"
        ]  #ヘルプの各ページ内容] #ヘルプの各ページ内容

        send_message = await message.channel.send(page_content_list[0]
                                                  )  #最初のページ投稿
        await send_message.add_reaction("➡")

        def help_react_check(reaction, user):
            '''
            ヘルプに対する、ヘルプリクエスト者本人からのリアクションかをチェックする
            '''
            emoji = str(reaction.emoji)
            if reaction.message.id != send_message.id:
                return 0
            if emoji == "➡" or emoji == "⬅":
                if user != message.author:
                    return 0
                else:
                    return 1

        while not client.is_closed():
            try:
                reaction, user = await client.wait_for('reaction_add',
                                                       check=help_react_check,
                                                       timeout=60.0)
            except asyncio.TimeoutError:
                await send_message.clear_reactions()
                msg_end = '\n ```State:Stop```'
                await send_message.edit(content=page_content_list[page_count] +
                                        msg_end)
                return  #時間制限が来たら、それ以降は処理しない
            else:
                emoji = str(reaction.emoji)
                if emoji == "➡" and page_count < 4:
                    page_count += 1
                if emoji == "⬅" and page_count > 0:
                    page_count -= 1

                await send_message.clear_reactions()  #事前に消去する
                msg_act = '\n ```State:Active```'
                await send_message.edit(content=page_content_list[page_count] +
                                        msg_act)

                if page_count == 0:
                    await send_message.add_reaction("➡")
                elif page_count == 1:
                    await send_message.add_reaction("⬅")
                    await send_message.add_reaction("➡")
                elif page_count == 2:
                    await send_message.add_reaction("⬅")
                    await send_message.add_reaction("➡")
                elif page_count == 3:
                    await send_message.add_reaction("⬅")
                    await send_message.add_reaction("➡")
                elif page_count == 4:
                    await send_message.add_reaction("⬅")
コード例 #4
0
ファイル: discordbot.py プロジェクト: 8ka1alu/saya-bot
async def on_message(message):
    if message.content == ("i)sinfo"):
        guild = message.guild
        role = next(c for c in guild.roles if c.name == '@everyone')
        t_locked = 0
        v_locked = 0
        online = 0
        offline = 0
        idle = 0
        dnd = 0
        pin = 0
        if guild.mfa_level == 0:
            mfamsg = "メンバーに2要素認証を必要としていません"
        else:
            mfamsg = "メンバーに2要素認証を必要としています"
        if guild.premium_subscription_count == None:
            pmmc = "0"
        else:
            pmmc = guild.premium_subscription_count
        for member in guild.members:
            if member.status == discord.Status.online:
                online += 1
            if member.status == discord.Status.offline:
                offline += 1
            if member.status == discord.Status.idle:
                idle += 1
            if member.status == discord.Status.dnd:
                dnd += 1
        for channel in guild.text_channels:
            if channel.overwrites_for(role).read_messages is False:
                t_locked += 1
        for channel in guild.voice_channels:
            if channel.overwrites_for(role).connect is False:
                v_locked += 1
        total = online + offline + idle + dnd
        if total > 499:
            large = "大"
        elif total > 249:
            large = "中"
        else:
            large = "小"
        embed = discord.Embed(title=f"サーバー情報", color=0x2ECC69)
        embed.set_thumbnail(url=guild.icon_url)
        embed.add_field(name="‣サーバー名", value=f"**{guild.name}**", inline=False)
        embed.add_field(name="‣サーバーの説明", value=f"**{guild.description}**", inline=False)
        embed.add_field(name="‣サーバーID", value=f"**{guild.id}**")

        embed.add_field(name="‣サーバーの大きさ", value=f"**{large}**")
        embed.add_field(name="‣サーバー地域", value=f"**{guild.region}**")
        embed.add_field(name="‣サーバーの旗", value=f"**{guild.banner}**")
        embed.add_field(name="‣オーナー", value=f"||**{guild.owner.mention}**||", inline=False)
        embed.add_field(name="‣チャンネル数",
                        value=f"総合チャンネル数 :**{len(guild.text_channels) + len(guild.voice_channels)}個**(🔒×**{t_locked + v_locked}**)\nテキストチャンネル:**{len(guild.text_channels)}個**(🔒×**{t_locked}**)\nボイスチャンネル :**{len(guild.voice_channels)}個**(🔒×**{v_locked}**)")
        embed.add_field(name="‣カテゴリー数", value=f"**全て:{len(guild.categories)}**")
        embed.add_field(name="‣役職数", value=f"**{len(guild.roles)}職**", inline=False)
        embed.add_field(name="‣メンバー数",
                        value=f"総メンバー:**{total}人**\nオンライン:**{online}人**\nオフライン:**{offline}人**\n退席中  :**{idle}人**\n取り込み中:**{dnd}人**",
                        inline=False)
        embed.add_field(name="‣サーバーのブースト状態",
                        value=f"サーバーブーストレベル :**Lv.{guild.premium_tier}**\nサーバーブーストユーザー:**{pmmc}人**", inline=False)
        embed.add_field(name="‣二段階認証", value=f"**{mfamsg}**", inline=False)
        embed.set_footer(text = datetime.now(JST))
        await message.channel.send(embed=embed)
     
    url_re = r"https://discordapp.com/channels/(\d{18})/(\d{18})/(\d{18})"
    url_list  = re.findall(url_re,message.content)
    
    for url in url_list:
        guild_id,channel_id,message_id = url
        channel = client.get_channel(int(channel_id))

        if channel is not None:
            got_message = await channel.fetch_message(message_id)

            if got_message is not None:
                await message.channel.send(embed=open_message(got_message))

    if message.author.bot:  # ボットを弾く。
        return

    if message.content.startswith("idc"):
        # 入力された内容を受け取る
        say = message.content 

        # [idc ]部分を消し、AdBのdで区切ってリスト化する
        order = say.strip('idc ')
        cnt, mx = list(map(int, order.split('d'))) # さいころの個数と面数
        dice = diceroll(cnt, mx) # 和を計算する関数(後述)
        await message.channel.send(dice[cnt])
        del dice[cnt]

        # さいころの目の総和の内訳を表示する
        await message.channel.send(dice)

    if message.content == 'irestart': 
        if message.author.id == great_owner_id:
            await message.channel.send('5秒後に再起動します')
            await client.change_presence(status=discord.Status.do_not_disturb,activity=discord.Game(name='再起動待機'))
            await asyncio.sleep(5)
            await client.logout()  
            os.execv(sys.executable,[sys.executable, os.path.join(sys.path[0], __file__)] + sys.argv[1:])  
        if not message.author.id == great_owner_id:
            await message.channel.send('貴方にこのコマンドの使用権限はありません')   

    if message.content == 'iclear': 
        if message.author.id == great_owner_id or message.author.id == saver_owner_id:
            await message.channel.purge()  
            await message.channel.send("ログを削除しました")
        if not message.author.id == great_owner_id:
            if not message.author.id == saver_owner_id:
                await message.channel.send('貴方にこのコマンドの使用権限はありません')   

    if 'おは' in message.content: #から始まるメッセージ
        #指定したチャンネルとメッセージを送ったチャンネルが同じIDなら実行
        if message.author.id == great_owner_id:
            await message.channel.send('おはようございます!開発者様!今日も一日頑張って下さい!')
        elif message.author.id == saver_owner_id:
            await message.channel.send('おはようございます!オーナーさん!今日も一日頑張って下さい!') 
        else:
            await message.channel.send(f"{message.author.mention} さん。おはようございます。") 

    if 'おやす' in message.content: #から始まるメッセージ
        #指定したチャンネルとメッセージを送ったチャンネルが同じIDなら実行
        if message.author.id == great_owner_id:
            await message.channel.send('おやすみなさい!開発者様!今日も一日お疲れさまでした!') 
        elif message.author.id == saver_owner_id:
            await message.channel.send('おやすみなさい!オーナーさん!今日も一日お疲れさまでした!') 
        else:
            await message.channel.send(f"{message.author.mention} さん。おやすみなさい。") 

    if message.content == "iset": #から始まるメッセージ
        guild = message.guild 
        member_count = sum(1 for member in guild.members if not member.bot)
        bot_count = sum(1 for member in guild.members if member.bot)
        #指定したチャンネルとメッセージを送ったチャンネルが同じIDなら実行
        if message.author.id == great_owner_id:
            await client.get_channel(member_count_ch).edit(name=f"User数:{str(member_count)}")
            await client.get_channel(bot_count_ch).edit(name=f"Bot数:{str(bot_count)}")
            await message.delete()
 
    global msg_count
    if not message.author.bot:
        msg_count += 1
        await client.get_channel(msg_count_ch).edit(name=f"発言数:{str(msg_count)}")
コード例 #5
0
ファイル: discordbot.py プロジェクト: 8ka1alu/n-doukou
async def on_message(message):
    """メッセージを処理"""
    if message.author.id == my_bot_id:
        return
#おみくじ
    if message.content == "おみくじ":
        if message.channel.id == CHANNEL_ID3 or CHANNEL_IDother:
            # Embedを使ったメッセージ送信 と ランダムで要素を選択
            embed = discord.Embed(
                title="おみくじ",
                description=f"{message.author.mention}さんの今日の運勢は!",
                color=0x2ECC69)
            embed.set_thumbnail(url=message.author.avatar_url)
            embed.add_field(name="[運勢] ",
                            value=random.choice(
                                ('大吉', '中吉', '小吉', '吉', '半吉', '末吉', '末小吉', '凶',
                                 '小凶', '半凶', '末凶', '大凶')),
                            inline=False)
            await message.channel.send(embed=embed)
            #client.get_channel(CHANNEL_ID3)

    if message.content == 'ratk':
        await message.channel.send('..atk')
    if message.content == 'rin':
        await message.channel.send('..in')
    if message.author.id == ssr_tuti:
        await client.get_channel(ssr_ch).send('..i in')
    if message.content == 'rmycoin':
        await message.channel.send('..mycoin')
    if message.content == 'rgatya':
        await message.channel.send('..gatya 100')
    if message.content == 'rlogin':
        await message.channel.send('..login')
    if message.content == 'rst':
        await message.channel.send('..st')

    if message.content == 'ヘルプ':
        page_count = 0  #ヘルプの現在表示しているページ数
        page_content_list = [
            ">>> **リリナコマンド一覧(ページ1)**\n\n**何時?**:今の時間を教えてくれます!(何時何分何秒)\n**何日?**:何日か教えてくれます!(何月何日)\n\n➡絵文字を押すと次のページへ",
            ">>> **リリナコマンド一覧(ページ2)**\n\n**!dc XdY**:Y面のダイスをX回振ります!\n**coin**:コイントスを行います。\n**スロット**:あなたは大当たりを引けるのか!?\n\n➡絵文字で次のページ\n⬅絵文字で前のページ",
            ">>> **リリナコマンド一覧(ページ3)**\n\n以下のコマンドは<#624496341124513793>で使えます。\n\n**おみくじ**or**御神籤**:おみくじが引けます!\n**運勢**:貴方の運勢は!\n\n➡絵文字で次のページ\n⬅絵文字で前のページ",
            ">>> **リリナコマンド一覧(ページ4)**\n\n以下のコマンドは__管理者権限__が必要\n**ステータス**:この鯖のステータスです。\n\n➡絵文字で次のページ\n⬅絵文字で前のページ",
            ">>> **このBOT詳細情報(ページ5)**\n\nBOT名前:" + f"{client.user.name}" +
            "\nBOT ID:" + f"{client.user.id}" + "\nDiscordバージョン:" +
            f"{discord.__version__}" + "\nDiscord.pyバージョン:" + discord_py_ver +
            "\n開発バージョン:" + ksi_ver +
            "\n開発者:<@459936557432963103>\n\n⬅絵文字で前のページ"
        ]  #ヘルプの各ページ内容] #ヘルプの各ページ内容

        send_message = await message.channel.send(page_content_list[0]
                                                  )  #最初のページ投稿
        await send_message.add_reaction("➡")

        def help_react_check(reaction, user):
            '''
            ヘルプに対する、ヘルプリクエスト者本人からのリアクションかをチェックする
            '''
            emoji = str(reaction.emoji)
            if reaction.message.id != send_message.id:
                return 0
            if emoji == "➡" or emoji == "⬅":
                if user != message.author:
                    return 0
                else:
                    return 1

        while not client.is_closed():
            try:
                reaction, user = await client.wait_for('reaction_add',
                                                       check=help_react_check,
                                                       timeout=60.0)
            except asyncio.TimeoutError:
                msg_end = '\n stop'
                await send_message.edit(content=page_content_list[page_count] +
                                        msg_end)
                return  #時間制限が来たら、それ以降は処理しない
            else:
                emoji = str(reaction.emoji)
                if emoji == "➡" and page_count < 4:
                    page_count += 1
                if emoji == "⬅" and page_count > 0:
                    page_count -= 1

                await send_message.clear_reactions()  #事前に消去する
                await send_message.edit(content=page_content_list[page_count])

                if page_count == 0:
                    await send_message.add_reaction("➡")
                elif page_count == 1:
                    await send_message.add_reaction("⬅")
                    await send_message.add_reaction("➡")
                elif page_count == 2:
                    await send_message.add_reaction("⬅")
                    await send_message.add_reaction("➡")
                elif page_count == 3:
                    await send_message.add_reaction("⬅")
                    await send_message.add_reaction("➡")
                elif page_count == 4:
                    await send_message.add_reaction("⬅")
                    #各ページごとに必要なリアクション

    if message.content == 'ヘルプクラス' or message.content == 'クラスヘルプ':
        page_count = 0  #ヘルプの現在表示しているページ数
        page_content_list = [
            ">>> **クラス一覧(ページ0)**\n\nこちらはクラスについての一覧です。\n\n目次\n<@&613345307861844011>についてはページ1\n<@&613345394033819649>についてはページ2\n<@&613345488166715392>についてはページ3\n<@&613345547344150538>についてはページ4\n\n総クラスリーダー:<@475909877018132500>\n\n各一覧の見方\nクラス名:クラス名\n特徴:クラスの特徴\nクラスリーダー:クラスリーダー\nコマンド:<#643070878652825601>で入力\n\n➡絵文字を押すとクラス説明へ",
            ">>> **クラス一覧(ページ1)**\n\nクラス名:<@&613345307861844011>(ザクセン)\n特徴:PS向上\nクラスリーダー:<@329673969806475275>\nコマンド:赤\n\n➡絵文字で次のクラス\n⬅絵文字で前の説明",
            ">>> **クラス一覧(ページ2)**\n\nクラス名:<@&613345394033819649>(クリミア)\n特徴:エンジョイ\nクラスリーダー:<@602460316806152192>と<@539430524020719628>\nコマンド:黄\n\n➡絵文字で次のクラス\n⬅絵文字で前のクラス",
            ">>> **クラス一覧(ページ3)**\n\nクラス名:<@&613345488166715392>(ロズヴィエルト)\n特徴:初心者\nクラスリーダー:<@493093867973902357>\nコマンド:緑\n\n➡絵文字で次のクラス\n⬅絵文字で前のクラス",
            ">>> **クラス一覧(ページ4)**\n\nクラス名:<@&613345547344150538>(ノルデック)\n特徴:配信OK\nクラスリーダー:<@540121769454075904>\nコマンド:青\n\n⬅絵文字で前のクラス"
        ]  #ヘルプの各ページ内容

        send_message = await message.channel.send(page_content_list[0]
                                                  )  #最初のページ投稿
        await send_message.add_reaction("➡")

        def help_react_check(reaction, user):
            '''
            ヘルプに対する、ヘルプリクエスト者本人からのリアクションかをチェックする
            '''
            emoji = str(reaction.emoji)
            if reaction.message.id != send_message.id:
                return 0
            if emoji == "➡" or emoji == "⬅":
                if user != message.author:
                    return 0
                else:
                    return 1

        while not client.is_closed():
            try:
                reaction, user = await client.wait_for('reaction_add',
                                                       check=help_react_check,
                                                       timeout=60.0)
            except asyncio.TimeoutError:
                msg_end = '\n stop'
                await send_message.edit(content=page_content_list[page_count] +
                                        msg_end)
                return  #時間制限が来たら、それ以降は処理しない
            else:
                emoji = str(reaction.emoji)
                if emoji == "➡" and page_count < 4:
                    page_count += 1
                if emoji == "⬅" and page_count > 0:
                    page_count -= 1

                await send_message.clear_reactions()  #事前に消去する
                await send_message.edit(content=page_content_list[page_count])

                if page_count == 0:
                    await send_message.add_reaction("➡")
                elif page_count == 1:
                    await send_message.add_reaction("⬅")
                    await send_message.add_reaction("➡")
                elif page_count == 2:
                    await send_message.add_reaction("⬅")
                    await send_message.add_reaction("➡")
                elif page_count == 3:
                    await send_message.add_reaction("⬅")
                    await send_message.add_reaction("➡")
                elif page_count == 4:
                    await send_message.add_reaction("⬅")
                    #各ページごとに必要なリアクション

    if message.content.startswith("スロット"):
        suroto = random.choice(
            ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))
        suroto1 = random.choice(
            ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))
        suroto2 = random.choice(
            ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))
        await asyncio.sleep(0.1)
        my_message = await message.channel.send('スロット結果がここに表示されます!')
        await asyncio.sleep(3)
        await my_message.edit(content='?|?|?')
        await asyncio.sleep(1)
        await my_message.edit(content=suroto + '|?|?')
        await asyncio.sleep(1)
        await my_message.edit(content=suroto + '|' + suroto1 + '|?')
        await asyncio.sleep(1)
        await my_message.edit(content=suroto + '|' + suroto1 + '|' + suroto2)
        if suroto == suroto1 == suroto2:
            await my_message.edit(content=suroto + '|' + suroto1 + '|' +
                                  suroto2 + '\n 結果:大当たり!!')
        elif suroto == suroto1 or suroto == suroto2 or suroto1 == suroto2:
            await my_message.edit(content=suroto + '|' + suroto1 + '|' +
                                  suroto2 + '\n 結果:リーチ!')
        else:
            await my_message.edit(content=suroto + '|' + suroto1 + '|' +
                                  suroto2 + '\n 結果:ハズレ')

    if message.content == 'coin sn1' or message.content == 'coin sn2':
        if message.author.id == great_owner_id:
            coin = random.choice(('●', '○'))
            if message.content == 'coin sn1':
                my_message = await message.channel.send('コイントスをします!')
                await asyncio.sleep(3)
                await my_message.edit(content='定義:○は表、●は裏')
                await asyncio.sleep(3)
                coinp = 0
                while coinp < 6:
                    await my_message.edit(content='抽選中:○```定義:○は表、●は裏```')
                    await asyncio.sleep(0.5)
                    await my_message.edit(content='抽選中:●```定義:○は表、●は裏```')
                    await asyncio.sleep(0.5)
                    coinp += 1
                await my_message.edit(content='抽選中: ```定義:○は表、●は裏```')
                await asyncio.sleep(2)
                await my_message.edit(content=' 結果:' + coin +
                                      '```定義:○は表、●は裏 \n adid:sn1```')
                return
            elif message.content == 'coin sn2':
                my_message = await message.channel.send('コイントスをします!')
                await asyncio.sleep(3)
                await my_message.edit(content='定義:●は表、○は裏')
                await asyncio.sleep(3)
                coinp = 0
                while coinp < 6:
                    await my_message.edit(content='抽選中:○```定義:●は表、○は裏```')
                    await asyncio.sleep(0.5)
                    await my_message.edit(content='抽選中:●```定義:●は表、○は裏```')
                    await asyncio.sleep(0.5)
                    coinp += 1
                await my_message.edit(content='抽選中: ```定義:●は表、○は裏```')
                await asyncio.sleep(2)
                await my_message.edit(content=' 結果:' + coin +
                                      '```定義:●は表、○は裏 \n adid:sn2```')
                return
        await message.channel.send('Error:You cannot use this command')
        return

    if message.content == 'coin':
        coin = random.choice(('●', '○'))
        coin1 = random.choice(('1', '2'))
        await asyncio.sleep(0.1)
        if coin1 == '1':
            my_message = await message.channel.send('コイントスをします!')
            await asyncio.sleep(3)
            await my_message.edit(content='定義:○は表、●は裏')
            await asyncio.sleep(3)
            coinp = 0
            while coinp < 6:
                await my_message.edit(content='抽選中:○```定義:○は表、●は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中:●```定義:○は表、●は裏```')
                await asyncio.sleep(0.5)
                coinp += 1
            await my_message.edit(content='抽選中: ```定義:○は表、●は裏```')
            await asyncio.sleep(2)
            await my_message.edit(content=' 結果:' + coin +
                                  '```定義:○は表、●は裏 \n adid:sn' + coin1 + '```')

            return
        elif coin1 == '2':
            my_message = await message.channel.send('コイントスをします!')
            await asyncio.sleep(3)
            await my_message.edit(content='定義:●は表、○は裏')
            await asyncio.sleep(3)
            coinp = 0
            while coinp < 6:
                await my_message.edit(content='抽選中:○```定義:●は表、○は裏```')
                await asyncio.sleep(0.5)
                await my_message.edit(content='抽選中:●```定義:●は表、○は裏```')
                await asyncio.sleep(0.5)
                coinp += 1
            await my_message.edit(content='抽選中: ```定義:●は表、○は裏```')
            await asyncio.sleep(2)
            await my_message.edit(content=' 結果:' + coin +
                                  '```定義:●は表、○は裏 \n adid:sn' + coin1 + '```')

            return
        await message.channel.send('Error')

#運勢
    if message.content == '運勢':
        if message.channel.id == CHANNEL_ID3 or CHANNEL_IDother:
            prob = random.random()

            if prob < 0.3:
                await message.channel.send('凶です……外出を控えることをオススメします')

            elif prob < 0.65:
                await message.channel.send('吉です!何かいい事があるかもですね!')

            elif prob < 0.71:
                await message.channel.send('末吉……どれくらい運がいいんでしょうね?•́ω•̀)?')

            elif prob < 0.76:
                await message.channel.send('半吉は吉の半分、つまり運がいいのです!')

            elif prob < 0.80:
                await message.channel.send('小吉ですね!ちょっと優しくされるかも?')

            elif prob < 0.83:
                await message.channel.send(
                    '吉の中で1番当たっても微妙に感じられる……つまり末吉なのです( ´・ω・`)')

            elif prob <= 1.0:
                await message.channel.send('おめでとうございます!大吉ですよ!(๑>∀<๑)♥')

    if message.content == '御神籤':
        if message.channel.id == CHANNEL_ID3 or CHANNEL_IDother:
            await asyncio.sleep(0.1)
            prob = random.random()

            if prob < 0.02:  #大凶
                await message.channel.send(
                    'https://cdn.discordapp.com/attachments/649413089778728970/655056313637666816/20191213233945.jpg'
                )

            elif prob < 0.10:  #凶
                await message.channel.send(
                    'https://cdn.discordapp.com/attachments/649413089778728970/655055945659056134/20191213233816.jpg'
                )

            elif prob < 0.35:  #吉
                await message.channel.send(
                    'https://cdn.discordapp.com/attachments/649413089778728970/655055610441891840/20191213233638.jpg'
                )

            elif prob < 0.55:  #半吉
                await message.channel.send(
                    'https://cdn.discordapp.com/attachments/649413089778728970/655054936773754890/20191213233418.jpg'
                )

            elif prob < 0.75:  #小吉
                await message.channel.send(
                    'https://cdn.discordapp.com/attachments/649413089778728970/655054736638345238/20191213233326.jpg'
                )

            elif prob < 0.95:  #末吉
                await message.channel.send(
                    'https://cdn.discordapp.com/attachments/649413089778728970/655054481956012046/20191213233205.jpg'
                )

            elif prob <= 1.0:  #大吉
                await message.channel.send(
                    'https://cdn.discordapp.com/attachments/649413089778728970/655051678499995651/20191213232052.jpg'
                )

    if message.content.startswith("!dc"):
        # 入力された内容を受け取る
        say = message.content

        # [!dc ]部分を消し、AdBのdで区切ってリスト化する
        order = say.strip('!dc ')
        cnt, mx = list(map(int, order.split('d')))  # さいころの個数と面数
        dice = diceroll(cnt, mx)  # 和を計算する関数(後述)
        await message.channel.send(dice[cnt])
        del dice[cnt]

        # さいころの目の総和の内訳を表示する
        await message.channel.send(dice)

    if message.content == 'ステータス':
        if message.author.guild_permissions.administrator:
            embed = discord.Embed(title="この鯖のステータス", description="Embed式")
            embed.add_field(name="サーバー名",
                            value=f'{message.guild.name}',
                            inline=False)
            embed.add_field(name="現オーナー名",
                            value=f'{message.guild.owner}',
                            inline=False)
            guild = message.guild
            member_count = sum(1 for member in guild.members if not member.bot)
            bot_count = sum(1 for member in guild.members if member.bot)
            all_count = (member_count) + (bot_count)
            embed.add_field(name="総人数", value=f'{all_count}', inline=False)
            embed.add_field(name="ユーザ数", value=f'{member_count}')
            embed.add_field(name="BOT数", value=f'{bot_count}')
            embed.add_field(name="テキストチャンネル数",
                            value=f'{len(message.guild.text_channels)}個',
                            inline=False)
            embed.add_field(name="ボイスチャンネル数",
                            value=f'{len(message.guild.voice_channels)}個',
                            inline=False)
            embed.set_thumbnail(url=message.guild.icon_url)
            await message.channel.send(embed=embed)

    if message.author.bot:  # ボットのメッセージをハネる
        return

    if client.user in message.mentions:  # 話しかけられたかの判定
        hensin = random.choice(
            ('よんだ?', 'なにー?', 'たべちゃうぞー!', 'がおー!', 'よろしくね', '!?'))
        reply = f'{message.author.mention} さん' + hensin + '```\n 私の機能が分からなかったら「ヘルプ」と打ってね☆```'  #返信メッセージの作成
        await message.channel.send(reply)  # 返信メッセージを送信

    if message.content.startswith("赤"):  #から始まるメッセージ
        #指定したチャンネルとメッセージを送ったチャンネルが同じIDなら実行
        if message.channel.id == lot_channel_id:
            role1 = discord.utils.get(message.guild.roles, name='class SAXONY')
            await message.author.add_roles(role1)
            role0 = discord.utils.get(message.guild.roles, name='class ticket')
            await message.author.remove_roles(role0)
            dm = await message.author.create_dm()
            await dm.send(
                f"{message.author.mention}さん! \n 「class-SAXONY」に参加しました。")
            await client.get_channel(lot_result_channel_id1).send(
                f'{message.author.mention} さんが参加しました!')
        if not message.channel.id == lot_channel_id:
            await message.delete()

    if message.content.startswith("黄"):  #から始まるメッセージ
        #指定したチャンネルとメッセージを送ったチャンネルが同じIDなら実行
        if message.channel.id == lot_channel_id:
            role2 = discord.utils.get(message.guild.roles,
                                      name='class CRIMEAN')
            await message.author.add_roles(role2)
            role0 = discord.utils.get(message.guild.roles, name='class ticket')
            await message.author.remove_roles(role0)
            dm = await message.author.create_dm()
            await dm.send(
                f"{message.author.mention}さん! \n 「class-CRIMEAN」に参加しました。")
            await client.get_channel(lot_result_channel_id2).send(
                f'{message.author.mention} さんが参加しました!')
        if not message.channel.id == lot_channel_id:
            await message.delete()

    if message.content.startswith("緑"):  #から始まるメッセージ
        #指定したチャンネルとメッセージを送ったチャンネルが同じIDなら実行
        if message.channel.id == lot_channel_id:
            role3 = discord.utils.get(message.guild.roles,
                                      name='class RUSVIET')
            await message.author.add_roles(role3)
            role0 = discord.utils.get(message.guild.roles, name='class ticket')
            await message.author.remove_roles(role0)
            dm = await message.author.create_dm()
            await dm.send(
                f"{message.author.mention}さん! \n 「class-RUSVIET」に参加しました。")
            await client.get_channel(lot_result_channel_id3).send(
                f'{message.author.mention} さんが参加しました!')
        if not message.channel.id == lot_channel_id:
            await message.delete()

    if message.content.startswith("青"):  #から始まるメッセージ
        #指定したチャンネルとメッセージを送ったチャンネルが同じIDなら実行
        if message.channel.id == lot_channel_id:
            role4 = discord.utils.get(message.guild.roles, name='class NORDIC')
            await message.author.add_roles(role4)
            role0 = discord.utils.get(message.guild.roles, name='class ticket')
            await message.author.remove_roles(role0)
            dm = await message.author.create_dm()
            await dm.send(
                f"{message.author.mention}さん! \n 「class NORDIC」に参加しました。")
            await client.get_channel(lot_result_channel_id4).send(
                f"{message.author.mention} さんが参加しました!")
        if not message.channel.id == lot_channel_id:
            await message.delete()

    now = datetime.datetime.now().strftime('%H')
    if now == '01':
        morning_txt = 'おはようです。ですが、まだ1:00ですよ。'
        evening_txt = 'おやすみなさい。良い夢見て下さいね。'
    elif now == '02':
        morning_txt = 'おはようです。ですが、まだ2:00ですよ。'
        evening_txt = 'おやすみなさい。良い夢見て下さいね。'
    elif now == '03':
        morning_txt = 'おはようです。ですが、まだ3:00ですよ。'
        evening_txt = 'おやすみなさい。夜更かしはあまり良くないですよ。'
    elif now == '04':
        morning_txt = 'おはようです。早起きは良いことです。'
        evening_txt = 'おやすみなさい。健康のため、もう少し早く寝ましょう。'
    elif now == '05':
        morning_txt = 'おはようです。早起きは良いことです。'
        evening_txt = 'おやすみなさい。もう5:00ですよ。'
    elif now == '06':
        morning_txt = 'おはようです。早起きは良いことです。'
        evening_txt = 'おやすみなさい。もう6:00ですよ。'
    elif now == '07':
        morning_txt = 'おはようです。良い朝ですね。'
        evening_txt = 'おやすみなさい。もう朝です。もっと早く眠れるようにしましょう。'
    elif now == '08':
        morning_txt = 'おはようです。朝食は何でしょう。パンかな。ご飯かな。'
        evening_txt = 'おやすみなさい。次の日が休みであっても、早く寝ましょう。'
    elif now == '09':
        morning_txt = 'おはようです。今日も一日頑張りましょう。'
        evening_txt = 'おやすみなさい。昼夜逆転生活はあまり良くありません。'
    elif now == '10':
        morning_txt = 'おはようです。今日も一日頑張りましょう。'
        evening_txt = 'おやすみなさい。この時間は起きていられるよう、早寝早起きを習慣付けましょう。'
    elif now == '11':
        morning_txt = 'おそようです。もう少し早く起きられるように頑張りましょう。'
        evening_txt = 'おやすみなさい。昼寝には少し早いようです。'
    elif now == '12':
        morning_txt = 'おそよーです。もうお昼ですよ。'
        evening_txt = 'おやすみなさい。軽い昼寝は20分程度がオススメです。'
    elif now == '13':
        morning_txt = 'おはようです。残り半日も頑張りましょう。'
        evening_txt = 'おやすみなさい。長めの昼寝は90分程度がオススメです。'
    elif now == '14':
        morning_txt = 'おはようです。14:00です。'
        evening_txt = 'おやすみなさい。長く寝過ぎないように。'
    elif now == '15':
        morning_txt = 'おはようです。今日のおやつは何かな?'
        evening_txt = 'おやすみなさい。長く寝過ぎないように。'
    elif now == '16':
        morning_txt = 'おはようです。長く寝過ぎるのは体には良くありません。'
        evening_txt = 'おやすみなさい。寝るにはまだ早いような気がします。'
    elif now == '17':
        morning_txt = 'おはようです。もう17:00ですよ。'
        evening_txt = 'おやすみなさい。まだ寝るには早いような気がします。'
    elif now == '18':
        morning_txt = 'おはようです。もう18:00。夕食時です。'
        evening_txt = 'おやすみなさい。まだまだ寝るには早いような気がします。'
    elif now == '19':
        morning_txt = 'おはようです。もう19:00。一日が終わりに近づいていますよ。'
        evening_txt = 'おやすみなさい。早寝は良いことです。'
    elif now == '20':
        morning_txt = 'おはようです。20:00です。これから夜がはじまります。'
        evening_txt = 'おやすみなさい。良い夢を見て下さい。'
    elif now == '21':
        morning_txt = 'おはようです。もう夜ですよ。今の生活を改めましょう。'
        evening_txt = 'おやすみなさい。良い夢を見ることを願っています。'
    elif now == '22':
        morning_txt = 'おはようです。まもなく日付が変わります。'
        evening_txt = 'おやすみなさい。明日も良い一日になるように。'
    elif now == '23':
        morning_txt = 'おはようです。まもなく日付が変わりますよ。'
        evening_txt = 'おやすみなさい。明日も頑張りましょう。'
    else:
        morning_txt = 'おはようです。起きるには早すぎます。'
        evening_txt = 'おやすみなさい。日付が変わりました。'

    if message.content.startswith("おはよ"):  #から始まるメッセージ
        #指定したチャンネルとメッセージを送ったチャンネルが同じIDなら実行
        if message.author.id == master_owner_id:
            await message.channel.send('おはようございます!マスターさん!今日も一日頑張って下さい!')
        if not message.author.id == master_owner_id:
            await message.channel.send(
                f"{message.author.mention} さん。{morning_txt}")

    if message.content.startswith("おやす"):  #から始まるメッセージ
        #指定したチャンネルとメッセージを送ったチャンネルが同じIDなら実行
        if message.author.id == master_owner_id:
            await message.channel.send('おやすみなさい!マスターさん!今日も一日お疲れさまでした!')
        if not message.author.id == master_owner_id:
            await message.channel.send(
                f"{message.author.mention} さん。{evening_txt}")


#年月日
    if message.content == '何日?':
        date = datetime.datetime.now()
        await message.channel.send(
            f'今日は{date.year}年{date.month}月{date.day}日です!')
    if message.content == '何時?':
        date = datetime.datetime.now()
        await message.channel.send(
            f'今は{date.hour}時{date.minute}分{date.second}秒だよ!')
    if message.content == '時計':
        weekdays = datetime.date.today().weekday()
        if weekdays == 0:
            weekday_name = "月曜日"
        elif weekdays == 1:
            weekday_name = "火曜日"
        elif weekdays == 2:
            weekday_name = "水曜日"
        elif weekdays == 3:
            weekday_name = "木曜日"
        elif weekdays == 4:
            weekday_name = "金曜日"
        elif weekdays == 5:
            weekday_name = "土曜日"
        elif weekdays == 6:
            weekday_name = "日曜日"
        else:
            weekday_name = "エラー"
        date = datetime.datetime.now()
        embed = discord.Embed(title="時計",
                              description="TimeZone(Japan)",
                              color=random.choice(
                                  (0, 0x1abc9c, 0x11806a, 0x2ecc71, 0x1f8b4c,
                                   0x3498db, 0x206694, 0x9b59b6, 0x71368a,
                                   0xe91e63, 0xad1457, 0xf1c40f, 0xc27c0e,
                                   0xe67e22, 0x95a5a6, 0x607d8b, 0x979c9f,
                                   0x546e7a, 0x7289da, 0x99aab5)))
        embed.add_field(
            name="日付",
            value=f'{date.year}年{date.month}月{date.day}日{weekday_name}',
            inline=False)
        embed.add_field(name="時間",
                        value=f'{date.hour}時{date.minute}分{date.second}秒',
                        inline=False)
        embed.set_thumbnail(
            url=
            "https://cdn.discordapp.com/attachments/688986679956340804/690461569854996490/180half_f.gif"
        )
        await message.channel.send(embed=embed)

    if message.content == '!restart':
        if message.author.id == great_owner_id:
            await message.channel.send('再起動します')
            await asyncio.sleep(0.5)
            await client.logout()
            os.execv(sys.executable,
                     [sys.executable,
                      os.path.join(sys.path[0], __file__)] + sys.argv[1:])
        if not message.author.id == great_owner_id:
            await message.channel.send('貴方にこのコマンドの使用権限はありません')
コード例 #6
0
ファイル: discordbot.py プロジェクト: 8ka1alu/tundras
async def on_message(message):

    if message.author.bot:  # ボットを弾く。
        return

    GLOBAL_CH_NAME = "破壊工房"  # グローバルチャットのチャンネル名
    GLOBAL_WEBHOOK_NAME = "hakai-webhook"  # グローバルチャットのWebhook名

    if message.channel.name == GLOBAL_CH_NAME:
        # hoge-globalの名前をもつチャンネルに投稿されたので、メッセージを転送する
        channels = client.get_all_channels()
        global_channels = [ch for ch in channels if ch.name == GLOBAL_CH_NAME]

        for channel in global_channels:
            ch_webhooks = await channel.webhooks()
            webhook = discord.utils.get(ch_webhooks, name=GLOBAL_WEBHOOK_NAME)

            if webhook is None:
                await message.channel.create_webhook(name=GLOBAL_WEBHOOK_NAME)
                continue
            if message.attachments:
                MSG = message.attachments[0].url
                embed = discord.Embed(
                    title="画像送信",
                    description=" ",
                    color=random.choice(
                        (0, 0x1abc9c, 0x11806a, 0x2ecc71, 0x1f8b4c, 0x3498db,
                         0x206694, 0x9b59b6, 0x71368a, 0xe91e63, 0xad1457,
                         0xf1c40f, 0xc27c0e, 0xe67e22, 0x95a5a6, 0x607d8b,
                         0x979c9f, 0x546e7a, 0x7289da, 0x99aab5)))
                embed.set_image(url=MSG)
                await webhook.send(
                    content=message.content,
                    embed=embed,
                    username=message.author.name,
                    avatar_url=message.author.avatar_url_as(format="png"))
                return
            else:
                #await message.delete()
                await webhook.send(
                    content=message.content,
                    username=message.author.name,
                    avatar_url=message.author.avatar_url_as(format="png"))
                return

    url_re = r"https://discordapp.com/channels/(\d{18})/(\d{18})/(\d{18})"
    url_list = re.findall(url_re, message.content)

    for url in url_list:
        guild_id, channel_id, message_id = url
        channel = client.get_channel(int(channel_id))

        if channel is not None:
            got_message = await channel.fetch_message(message_id)

            if got_message is not None:
                await message.channel.send(embed=open_message(got_message))

    if message.channel.name == GLOBAL_CH_NAME:
        return

    if message.content == ("nsinfo"):
        guild = message.guild
        role = next(c for c in guild.roles if c.name == '@everyone')
        t_locked = 0
        v_locked = 0
        online = 0
        offline = 0
        idle = 0
        dnd = 0
        pin = 0
        if guild.mfa_level == 0:
            mfamsg = "メンバーに2要素認証を必要としていません"
        else:
            mfamsg = "メンバーに2要素認証を必要としています"
        if guild.premium_subscription_count == None:
            pmmc = "0"
        else:
            pmmc = guild.premium_subscription_count
        for member in guild.members:
            if member.status == discord.Status.online:
                online += 1
            if member.status == discord.Status.offline:
                offline += 1
            if member.status == discord.Status.idle:
                idle += 1
            if member.status == discord.Status.dnd:
                dnd += 1
        for channel in guild.text_channels:
            if channel.overwrites_for(role).read_messages is False:
                t_locked += 1
        for channel in guild.voice_channels:
            if channel.overwrites_for(role).connect is False:
                v_locked += 1
        total = online + offline + idle + dnd
        if total > 499:
            large = "大"
        elif total > 249:
            large = "中"
        else:
            large = "小"
        embed = discord.Embed(title=f"サーバー情報", color=0x2ECC69)
        embed.set_thumbnail(url=guild.icon_url)
        embed.add_field(name="‣サーバー名", value=f"**{guild.name}**", inline=False)
        embed.add_field(name="‣サーバーの説明",
                        value=f"**{guild.description}**",
                        inline=False)
        embed.add_field(name="‣サーバーID", value=f"**{guild.id}**")

        embed.add_field(name="‣サーバーの大きさ", value=f"**{large}**")
        embed.add_field(name="‣サーバー地域", value=f"**{guild.region}**")
        embed.add_field(name="‣サーバーの旗", value=f"**{guild.banner}**")
        embed.add_field(name="‣オーナー",
                        value=f"||**{guild.owner.mention}**||",
                        inline=False)
        embed.add_field(
            name="‣チャンネル数",
            value=
            f"総合チャンネル数 :**{len(guild.text_channels) + len(guild.voice_channels)}個**(🔒×**{t_locked + v_locked}**)\nテキストチャンネル:**{len(guild.text_channels)}個**(🔒×**{t_locked}**)\nボイスチャンネル :**{len(guild.voice_channels)}個**(🔒×**{v_locked}**)"
        )
        embed.add_field(name="‣カテゴリー数",
                        value=f"**全て:{len(guild.categories)}**")
        embed.add_field(name="‣役職数",
                        value=f"**{len(guild.roles)}職**",
                        inline=False)
        embed.add_field(
            name="‣メンバー数",
            value=
            f"総メンバー:**{total}人**\nオンライン:**{online}人**\nオフライン:**{offline}人**\n退席中  :**{idle}人**\n取り込み中:**{dnd}人**",
            inline=False)
        embed.add_field(
            name="‣サーバーのブースト状態",
            value=
            f"サーバーブーストレベル :**Lv.{guild.premium_tier}**\nサーバーブーストユーザー:**{pmmc}人**",
            inline=False)
        embed.add_field(name="‣二段階認証", value=f"**{mfamsg}**", inline=False)
        embed.set_footer(text=datetime.now(JST))
        await message.channel.send(embed=embed)

    if message.content.startswith("ndc"):
        # 入力された内容を受け取る
        say = message.content

        # [idc ]部分を消し、AdBのdで区切ってリスト化する
        order = say.strip('ndc ')
        cnt, mx = list(map(int, order.split('d')))  # さいころの個数と面数
        dice = diceroll(cnt, mx)  # 和を計算する関数(後述)
        await message.channel.send(dice[cnt])
        del dice[cnt]

        # さいころの目の総和の内訳を表示する
        await message.channel.send(dice)

    if message.content == 'nrestart':
        if message.author.id == great_owner_id:
            await message.channel.send('5秒後に再起動します')
            await client.change_presence(status=discord.Status.do_not_disturb,
                                         activity=discord.Game(name='再起動待機'))
            await asyncio.sleep(5)
            await client.logout()
            os.execv(sys.executable,
                     [sys.executable,
                      os.path.join(sys.path[0], __file__)] + sys.argv[1:])
        if not message.author.id == great_owner_id:
            await message.channel.send('貴方にこのコマンドの使用権限はありません')

    if message.content == 'nclear':
        if message.author.id == great_owner_id or message.author.id == saver_owner_id:
            await message.channel.purge()
            await message.channel.send("ログを削除しました")
        if not message.author.id == great_owner_id:
            if not message.author.id == saver_owner_id:
                await message.channel.send('貴方にこのコマンドの使用権限はありません')

    if 'おは' in message.content:  #から始まるメッセージ
        #指定したチャンネルとメッセージを送ったチャンネルが同じIDなら実行
        if message.author.id == great_owner_id:
            await message.channel.send('おはようございます!開発者様!今日も一日頑張って下さい!')
        elif message.author.id == saver_owner_id:
            await message.channel.send('おはようございます!オーナーさん!今日も一日頑張って下さい!')
        else:
            await message.channel.send(
                f"{message.author.mention} さん。おはようございます。")

    if 'おやす' in message.content:  #から始まるメッセージ
        #指定したチャンネルとメッセージを送ったチャンネルが同じIDなら実行
        if message.author.id == great_owner_id:
            await message.channel.send('おやすみなさい!開発者様!今日も一日お疲れさまでした!')
        elif message.author.id == saver_owner_id:
            await message.channel.send('おやすみなさい!オーナーさん!今日も一日お疲れさまでした!')
        else:
            await message.channel.send(f"{message.author.mention} さん。おやすみなさい。")

    global msg_count
    if message.guild.id == 628566224460185630:
        return
    if not message.author.bot:
        msg_count += 1
        await client.change_presence(
            status=discord.Status.idle,
            activity=discord.Game(name=f'発言数:{msg_count}'))