作りたいもの
指定した時間に挨拶をするdiscordのbot
現状
pythonでdiscordのbotを作っていて、webサイトを参考にしているのですがbotを自ら発言させる方法がわからなくて困っています。
作ってみたコード
python import discord # インストールした discord.py import time from time import sleep import threading client = discord.Client() # 接続に使用するオブジェクト async def login_status_message(): while True: if time.strftime('%H:%M:%S',time.localtime())=='21:00:00': channel = client.get_channel('チャンネルID') await client.send_message(channel, '勝手に喋るよ') sleep(5) # 起動時に通知してくれる処理 @client.event async def on_ready(): print('ログインしました') @client.event async def on_message(message): if message.content.startswith('挨拶して'): reply = 'こんにちは' await client.send_message(message.channel, reply) # botの接続と起動 # (tokenにはbotアカウントのアクセストークンを入れてください) client.run('トークン')
下段で書いてる「挨拶して」という言葉に対して「こんにちは」と返すプログラムは機能しました。
上段では21時に任意のチャンネルに「勝手に喋るよ」とbotを発言させるつもりだったのですが上手くいきませんでした。
webサイトで出ていた部分を切り取って書いてたりしてので正直これで合っているかもわからないです。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/11/18 13:03