Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- from discord.ext import commands
- from discord import Embed
- import asyncio
- import datetime
- import aiofiles
- print('Discord bot サーバーに接続中...\nConncting Discord bot server...\n-----')
- client=commands.Bot(command_prefix='!')
- @client.event
- async def on_ready():
- await client.change_presence(status=discord.Status.online,activity=discord.Game('試験中'))
- print('Discord botサーバーに正常接続しました\nSuccessfully server connected\n-----')
- @client.event
- async def on_message(message):
- if message.content.startswith('v'):
- embed=discord.Embed(title='投票を開始します',url='https://bit.ly/2JahfiF',description=f'__{message.content[2:]}__', color=0x0048ff)
- embed.add_field(name="投票をキャンセルしたい場合", value="❌リアクションを追加して下さい", inline=False)
- embed.set_footer(text="投票は120分で締め切ります")
- channel = message.channel
- sent_msg = msg=await channel.send(f'{message.author.mention}さんが投票を作成しました',embed=embed)
- await msg.add_reaction('❌')
- await msg.add_reaction('👍')
- await msg.add_reaction('🤔')
- await msg.add_reaction('👎')
- def reaction_check(reaction, user):
- are_same_messages = reaction.message.channel == sent_msg.channel and reaction.message.id == sent_msg.id
- return user == message.author and str(reaction.emoji) == '❌' and are_same_messages
- try:
- reaction, user = await client.wait_for('reaction_add',timeout=7200,check=reaction_check)
- except asyncio.TimeoutError:
- await channel.send('__**投票が終了しました**__')
- else:
- embed=discord.Embed(title="投票を中止しました",url='https://bit.ly/2JahfiF', description="キャンセルが実行された為取り消しになりました", color=0xff0000)
- embed.add_field(name="キャンセル内容", value=f"_```{message.content[2:]}```_", inline=True)
- embed.add_field(name="投票開始ユーザー", value=f"{message.author.mention}", inline=True)
- embed.set_footer(text='投票キャンセルを受け付けました')
- await channel.purge(limit=2)
- await channel.send(f'{message.author.mention}',embed=embed)
- elif message.content.startswith('c'):
- embed=discord.Embed(title='メッセージを削除しますか?',url='https://bit.ly/2JahfiF',description=f'__10メッセージ__', color=0x0048ff)
- embed.add_field(name="削除すると復元は出来ません", value="了承するには☑️を押してください", inline=False)
- embed.set_footer(text='3分経過で自動的にキャンセルされます')
- channel = message.channel
- sent_msg = msg=await channel.send(f'{message.author.mention}',embed=embed)
- await msg.add_reaction('☑️')
- def reaction_check(reaction, user):
- are_same_messages = reaction.message.channel == sent_msg.channel and reaction.message.id == sent_msg.id
- return user == message.author and str(reaction.emoji) == '☑️' and are_same_messages
- try:
- reaction, user = await client.wait_for('reaction_add',timeout=720,check=reaction_check)
- except asyncio.TimeoutError:
- await channel.send('__**タイムアウトによりキャンセルされました**__')
- else:
- await channel.purge(limit=10)
- embed=discord.Embed(title="メッセージを削除しました",url='https://bit.ly/2JahfiF', description="正常に実行されました", color=0xff0000)
- embed.add_field(name="削除数", value=f"_```10```_", inline=True)
- embed.add_field(name="ユーザー", value=f"{message.author.mention}", inline=True)
- embed.set_footer(text='復元は出来ません')
- await channel.send(f'{message.author.mention}',embed=embed)
- client.run('TOKEN')
Add Comment
Please, Sign In to add comment