LoginSignup
4
5

More than 3 years have passed since last update.

俺の書いたPythonのdiscordbotのコード!

Last updated at Posted at 2021-01-29

中身

main.py
import discord
import os
import asyncio

# 接続に必要なオブジェクトを生成
client = discord.Client()

version = "1.0"
noeconsole=input

@client.event
# botが起動したときに動作する処理
async def on_ready():
    # 起動したらログイン通知が表示される
    print('ログインしました')
    print("erroがないか確認してください")
    await client.change_presence(activity=discord.Game
    (name="versionは"+(version)+"です。", ))
    await client.get_channel(782243365982175252).send("bot is online")

# botがメッセージを受信したときに動作する処理
@client.event
async def on_message(message):
    if message.author.id == 302050872383242240:
      if 'https://disboard.org' in message.embeds[0].description:
        await message.channel.send('べ、別にbumpしてくれたってうれしくねーぞ///')
      else:

        await message.channel.send('あれれぇ?時間わからないのかなぁ?') 

    # メッセージ送信者がBotだった場合は無視する
    if message.author.bot:
        return
    # ans のメッセージに対し ans と送信する
    if message.content == 'やっほー':
      await message.channel.send("あそぼ")
    if message.content == 'ねえねえ':
      await message.channel.send('どうした?')
    if message.content == 'おやすみ':
      await message.channel.send('おやすみー')
    #以下にコードを書いていく 
    if message.content.startswith("p."): #ここは自由に変えてね
        query = message.content[2:].split(" ") #空白で区切る
        if query[0] == "timerh": #ここも自由にかえてね
            await message.channel.send("timer start")#ここも自由に変えてね
            if int(query[1]) > 60:
              await message.channel.send('1時間以上は設定できません!')#ここも(ry
            else:
              await asyncio.sleep(int(query[1])*60) #分を取得&60倍
              await message.channel.send(f"{int(query[1])}分経ちました") #こ(ry
      #ここから下はおんなじ感じのコード
        if query[0] == "timer": #コマンドを判定
            await message.channel.send("timer start")
            if int(query[1]) > 3600:
              await message.channel.send('1時間以上は設定できません!')
            else:
              await asyncio.sleep(int(query[1])) #分を取得&60倍
              await message.channel.send(f"{int(query[1])}秒経ちました") #内容を変更

        elif query[0] == "say": #コマンドその2
            await message.channel.send(query[1])
        else:
            await message.channel.send(">>> 不明なコマンドです。")


client.run('#ここにbotのトークン入れてね')

宣伝

「プログラミングがしたい!」「わからないところがある!」って人は
Glanz code
に参加してね!

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5