前提・実現したいこと
ここに質問の内容を詳しく書いてください。
身内のサーバーでdiscodeでまず最初に天気や返答をしてくれるbotを作り正常に動いたため、音楽botとしての役割もつけようと思いいざ実行すると音楽は流すことに成功はしたが天気のことや返答をしてくれなくなった。
発生している問題・エラーメッセージ
Ignoring exception in on_message Traceback (most recent call last): File "C:\Users\show2\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 227, in _run_event await coro(*args, **kwargs) File "C:\Users\show2\Documents\ymd1go\yuuta3.py", line 34, in on_message await client.send_message(message.channel, reply) AttributeError: 'Client' object has no attribute 'send_message' [ERROR:bot] Exception in on_voice_state_update Traceback (most recent call last): File "C:\Users\show2\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 227, in _run_event await coro(*args, **kwargs) File "C:\Users\show2\Documents\Musicbot\MusicBot\musicbot\bot.py", line 2824, in on_voice_state_update player = await self.get_player(channel) File "C:\Users\show2\Documents\Musicbot\MusicBot\musicbot\bot.py", line 424, in get_player 'Use %ssummon to summon it to your voice channel.' % self.config.command_prefix) musicbot.exceptions.CommandError: The bot is not in a voice channel. Use !summon to summon it to your voice channel.
該当のソースコード
ソースコード import discord # インストールした discord.py import urllib.request import json import re client = discord.Client() # 接続に使用するオブジェクト citycodes = { "土浦": '080020', "水戸": '080010', "札幌": '016010', "仙台": '040010', "東京": '130010', "横浜": '140010', "名古屋": '230010', "大阪": '270000', "広島": '340010', "福岡": '400010', "鹿児島": '460010', "那覇": '471010', "岐阜": '210010', } # 起動時に通知してくれる処理 @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) if message.content.startswith("おはよう"): # 送り主がBotだった場合反応したくないので if client.user != message.author: m = "おはようございます" + message.author.name + "さん!" # メッセージが送られてきたチャンネルへメッセージを送ります await client.send_message(message.channel, m) if message.author != client.user: reg_res = re.compile(u"(.+)の天気").search(message.content) if reg_res: if reg_res.group(1) in citycodes.keys(): citycode = citycodes[reg_res.group(1)] resp = urllib.request.urlopen('http://weather.livedoor.com/forecast/webservice/json/v1?city=%s'%citycode).read() resp = json.loads(resp.decode('utf-8')) msg = resp['location']['city'] msg += "の天気は、\n" for f in resp['forecasts']: msg += f['dateLabel'] + "が" + f['telop'] + "\n" msg += "です。" await client.send_message(message.channel, message.author.mention + msg) else: await client.send_message(message.channel, "そこの天気はわかりません...") # botの接続と起動 client.run('トークン')
試したこと
特になし
補足情報
音楽Botはこのサイトを丸パクリしました。https://tech.kunimaly.com/how-to-setup-python-musicbot/
対話?返事をしてくれるBotを作った時には正常に動いてくれて音楽も両立させようとしたらエラーが起きました
音楽botを入れる際に、discord.pyの新しいバージョン(というかブランチ)がpipで入れられているからです。
ここでは、大幅なインターフェースの変更が入っており、古いバージョンで動くbot達は書き換えが必要になっていくようです。今回だと、従来のsend_messageがなくなっていてエラーになってるようですね。
↓変更点みたいなの
https://discordpy.readthedocs.io/ja/rewrite/migrating.html
あなたの回答
tips
プレビュー