When I was making a bot to show the weather on Discord.py, I got the following error.

Asked 2 years ago, Updated 2 years ago, 149 views

Actual Code

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+="The weather is \n"
      for fin resp ['foreecasts']:
        msg+=f['dateLabel']+" is "+f['telop']+"\n"
      msg+="."

      wait message.channel.send (message.channel, message.author.ment+msg)

client.run("token")

Error Displayed

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
    wait coro (*args, **kwargs)
  File "C:\Users\yoich\OneDrive\Desktop\bot General\Weathertest.py", line 27, in on_message
    wait message.channel.send (message.channel, message.author.ment+msg)
TypeError: send() takes from 1 to 2 positional arguments but 3 where given

Where and how can I start it normally?Python uses python3

python python3 discord

2022-09-30 21:38

1 Answers

If you change the send() part to the following, it will work.

wait message.channel.send(message.author.ment+msg)

send() is a method in the message.channel class, so you have an implicit argument of self.Therefore, the original call was to pass three arguments, including self, and the error send() takes from 1 to 2 positional arguments but 3 where given appears.


2022-09-30 21:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.