
前提
if message.content.startswith(' '):
を使用したのですが ' ' 内のキーワードを入れても反応がありません。
bot自体は起動します。
実現したいこと
メッセージを送信できるようにしたい
発生している問題・エラーメッセージ
@client.event async def on_message(message): if message.author.bot: return if message.content.startswith('おはよう'): await message.channel.send(f'{message.author.mention} さん!おはようございます!') if message.content.startswith('だめ'): dame = message.author.name + "良いです!" await message.channel.send(dame)
該当のソースコード
python
1import discord 2import random 3 4from discord.ext import commands 5from discord import Embed 6import asyncio 7import datetime 8 9from discord import app_commands 10from discord.ui import Modal, View, text_input 11from discord.ext import tasks 12 13client = discord.Client(intents=discord.Intents.default()) 14intents = discord.Intents.default() 15intents.message_content = True 16 17@client.event 18async def on_ready(): 19 20 print('おはようございます!!') 21 22 ch_id = xxxxxxxxxxxxxxxxxxxx 23 24 channel = client.get_channel(ch_id) 25 26 t = time.time() 27 local_time = time.localtime(t) 28 asc_time = time.asctime(local_time) 29 await channel.send(f"起動完了!{datetime.datetime.strptime(asc_time, '%a %b %d %H:%M:%S %Y')}") 30 31@client.event 32async def on_message(message): 33 if message.author.bot: 34 return 35 # 単純な応答 36 if message.content.startswith('おはよう'): 37 await message.channel.send(f'{message.author.mention} さん!おはようございます!') 38 39 if message.content.startswith('だめ'): 40 lose = message.author.name + "良いです!" 41 await message.channel.send(lose) 42 43 if client.user in message.mentions: 44 reply = f'{message.author.mention} さん!うるさいですよ!' 45 await message.channel.send(reply) 46 47client.run('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
補足情報(FW/ツールのバージョンなど)
pythonのバージョンは3.9、discord.pyのバージョンは2.0.0です。
channel.send()は動作します。
コードは汚いです。すみません。


回答1件
あなたの回答
tips
プレビュー