create account

make Discord bot / Discord botを作ろう by soyboy

View this thread on: hive.blogpeakd.comecency.com
· @soyboy ·
$0.35
make 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')
👍  , ,
properties (23)
authorsoyboy
permlinkmake-discord-bot-discord-bot
categorybusy
json_metadata{"community":"busy","app":"busy/2.3.0","format":"markdown","tags":["busy","discord","python"],"links":["/trending/general","/trending/general","/@client.event","/@client.event","/@client.event"],"users":["client.event"]}
created2018-02-03 02:24:09
last_update2018-02-03 02:24:09
depth0
children0
last_payout2018-02-10 02:24:09
cashout_time1969-12-31 23:59:59
total_payout_value0.285 HBD
curator_payout_value0.066 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,465
author_reputation400,487,599,076
root_title"make Discord bot / Discord botを作ろう"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id34,537,649
net_rshares55,131,287,660
author_curate_reward""
vote details (3)