make Discord bot / Discord botを作ろう
busy·@soyboy·
0.000 HBDmake Discord bot / Discord botを作ろう
it's my memorandum. respond to specific commands within Discord & when someone comes in the channel, bot write guidance to #general. 自分に対する備忘録。 Discord内で特定のコマンドに反応 & 誰かがチャンネルに入ってきたら #generalに案内文を書くbotを作成する。 ####### # coding: Shift_JIS ####### # coding: cp932 ####### # coding: EUC-JP ####### # coding: UTF-8 import discord import asyncio public_channel = 'general' mod_channel = None client = discord.Client() @client.event async def on_ready(): print('Logged in as') print(client.user.name) print(client.user.id) print('------') @client.event async def on_message(message): if message.content.startswith('!test'): counter = 0 public_channel = message.channel tmp = await client.send_message(message.channel, 'Calculating messages...') async for log in client.logs_from(message.channel, limit=100): if log.author == message.author: counter += 1 await client.edit_message(tmp, 'You have {} messages.'.format(counter)) print(public_channel) elif message.content.startswith('!sleep'): await asyncio.sleep(5) await client.send_message(message.channel, 'don't sleep') @client.event async def on_member_join(member): print(member) channel_bot_test = [channel for channel in client.get_all_channels() if channel.name == 'general'][0] await client.send_message(channel_bot_test, 'welcome sentence') client.run('write your bot ID')