前提・実現したいこと
bot.send()
Discord.pyを使用してBotを立てているのですが、そのBotを任意のタイミングでテキストチャンネルで発言させたい場合どのように処理を書けばいいのかわからず迷っています。
任意の処理のタイミングで実行しようとしたとき、以下のようなエラーが発生してしまします。
asyncio.run(bot.send())
という風にもやってみましたが以下のようなエラーが発生してしまいます。
発生している問題・エラーメッセージ
bot.send()
E:/xxxx/DiscordClient.py:39: RuntimeWarning: coroutine 'Discord.send' was never awaited bot.send() RuntimeWarning: Enable tracemalloc to get the object allocation traceback BOTが起動しました
asyncio.run(bot.send())
Traceback (most recent call last): File "E:/xxx/DiscordClient.py", line 39, in <module> asyncio.run(bot.send()) File "C:\xxx\anaconda3\lib\asyncio\runners.py", line 43, in run return loop.run_until_complete(main) File "C:\xxx\anaconda3\lib\asyncio\base_events.py", line 616, in run_until_complete return future.result() File "E:/xxx/DiscordClient.py", line 25, in send await self.get_channel(xxx).send("test") AttributeError: 'NoneType' object has no attribute 'send' Process finished with exit code 1
該当のソースコード
python
1from rich import print 2import discord 3from discord import Colour 4import asyncio 5 6 7class Discord(discord.Client): 8 TOKEN = f"xxxxx" 9 10 def __init__(self): 11 super(Discord, self).__init__() 12 self.token = self.TOKEN 13 14 async def on_ready(self): 15 print("BOTが起動しました") 16 17 async def on_message(self, message): 18 author = message.author 19 if author == self.user: 20 return 21 await message.channel.send("Hi") 22 23 async def send(self): 24 await self.get_channel(xxxx).send("test message") 25 26 27bot = Discord() 28 29#################ここが問題############### 30bot.send() 31########################################### 32 33bot.run(bot.TOKEN)
補足情報(FW/ツールのバージョンなど)
参考にした discord.pyのリファレンス
Python 3.8
discord.py-1.7.3
Windows 10
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。