SevenC_nanashi

修正後

Dec 8th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.99 KB | None | 0 0
  1. import discord
  2. from discord.ext import commands
  3. from discord import Embed
  4. import asyncio
  5. import datetime
  6. import aiofiles
  7.  
  8.  
  9. print('Discord bot サーバーに接続中...\nConncting Discord bot server...\n-----')
  10.  
  11. client=commands.Bot(command_prefix='!')
  12.  
  13. @client.event
  14. async def on_ready():
  15.     await client.change_presence(status=discord.Status.online,activity=discord.Game('試験中'))
  16.     print('Discord botサーバーに正常接続しました\nSuccessfully server connected\n-----')
  17.    
  18.  
  19. @client.event
  20. async def on_message(message):
  21.     if message.content.startswith('v'):
  22.         embed=discord.Embed(title='投票を開始します',url='https://bit.ly/2JahfiF',description=f'__{message.content[2:]}__', color=0x0048ff)
  23.         embed.add_field(name="投票をキャンセルしたい場合", value="❌リアクションを追加して下さい", inline=False)
  24.         embed.set_footer(text="投票は120分で締め切ります")
  25.         channel = message.channel
  26.         sent_msg = msg=await channel.send(f'{message.author.mention}さんが投票を作成しました',embed=embed)
  27.         await msg.add_reaction('❌')
  28.         await msg.add_reaction('👍')
  29.         await msg.add_reaction('🤔')
  30.         await msg.add_reaction('👎')
  31.         def reaction_check(reaction, user):
  32.             are_same_messages = reaction.message.channel == sent_msg.channel and reaction.message.id == sent_msg.id
  33.             return user == message.author and str(reaction.emoji) == '❌'  and are_same_messages
  34.  
  35.         try:
  36.             reaction, user = await client.wait_for('reaction_add',timeout=7200,check=reaction_check)
  37.         except asyncio.TimeoutError:
  38.             await channel.send('__**投票が終了しました**__')
  39.         else:
  40.             embed=discord.Embed(title="投票を中止しました",url='https://bit.ly/2JahfiF', description="キャンセルが実行された為取り消しになりました", color=0xff0000)
  41.             embed.add_field(name="キャンセル内容", value=f"_```{message.content[2:]}```_", inline=True)
  42.             embed.add_field(name="投票開始ユーザー", value=f"{message.author.mention}", inline=True)
  43.             embed.set_footer(text='投票キャンセルを受け付けました')
  44.             await channel.purge(limit=2)
  45.             await channel.send(f'{message.author.mention}',embed=embed)        
  46.     elif message.content.startswith('c'):
  47.         embed=discord.Embed(title='メッセージを削除しますか?',url='https://bit.ly/2JahfiF',description=f'__10メッセージ__', color=0x0048ff)
  48.         embed.add_field(name="削除すると復元は出来ません", value="了承するには☑️を押してください", inline=False)
  49.         embed.set_footer(text='3分経過で自動的にキャンセルされます')
  50.         channel = message.channel
  51.         sent_msg = msg=await channel.send(f'{message.author.mention}',embed=embed)
  52.         await msg.add_reaction('☑️')
  53.         def reaction_check(reaction, user):
  54.             are_same_messages = reaction.message.channel == sent_msg.channel and reaction.message.id == sent_msg.id
  55.             return user == message.author and str(reaction.emoji) == '☑️'  and are_same_messages
  56.  
  57.         try:
  58.             reaction, user = await client.wait_for('reaction_add',timeout=720,check=reaction_check)
  59.         except asyncio.TimeoutError:
  60.             await channel.send('__**タイムアウトによりキャンセルされました**__')
  61.         else:
  62.             await channel.purge(limit=10)
  63.             embed=discord.Embed(title="メッセージを削除しました",url='https://bit.ly/2JahfiF', description="正常に実行されました", color=0xff0000)
  64.             embed.add_field(name="削除数", value=f"_```10```_", inline=True)
  65.             embed.add_field(name="ユーザー", value=f"{message.author.mention}", inline=True)
  66.             embed.set_footer(text='復元は出来ません')
  67.             await channel.send(f'{message.author.mention}',embed=embed)        
  68.  
  69. client.run('TOKEN')
Add Comment
Please, Sign In to add comment