0

実際のコード

import discord
import urllib.request
import json
import re

client = discord.Client()

citycode = '016010'
resp = urllib.request.urlopen('http://weather.livedoor.com/forecast/webservice/json/v1?city=%s'%citycode).read()
resp = json.loads(resp.decode('utf-8'))

@client.event
async def on_ready():
  print("logged in as " + client.user.name)

@client.event
async def on_message(message):
  if message.author != client.user:

    if message.content == "weather":
      msg = resp['location']['city']
      msg += "の天気は、\n"
      for f in resp['forecasts']:
        msg += f['dateLabel'] + "が" + f['telop'] + "\n"
      msg += "です。"

      await message.channel.send(message.channel, message.author.mention + msg)

client.run("token")

表示されたエラー

Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\yoich\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\client.py", line 227, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\yoich\OneDrive\Desktop\bot総合\Weathertest.py", line 27, in on_message
    await message.channel.send(message.channel, message.author.mention + msg)
TypeError: send() takes from 1 to 2 positional arguments but 3 were given

どこをどうすれば正常に起動するのでしょうか?Pythonはpython3を使っています

3

1 件の回答 1

1

send() の部分を次のように変えると動きそうです。

await message.channel.send(message.author.mention + msg)

send()message.channel クラスのメソッドなので、暗黙的な引数として self を持っています。したがって元々の呼び出し方だと self も含めて 3 引数渡していたことになり、send() takes from 1 to 2 positional arguments but 3 were given というエラーが出ています。

この質問に回答するには、ログインする必要があります。