Aprocryphan
Aprocryphan

Reputation: 23

send() takes from 1 to 2 positional arguments but 3 were given (discord.py)

i am trying to make it say the name of the user that did ~milk, it only produces the error when you type in discord ~milk here is the code that produces the error:

async def on_message(message):
   if message.author == client.user:
       return
   if message.content.startswith('~milk'):
       await message.channel.send(message.author, 'is blessed by the Baltic Gods of Dairy')

Upvotes: 1

Views: 2284

Answers (3)

ChocolateEye
ChocolateEye

Reputation: 46

send() takes only 1 to 2 positional arguments meaning it could be either send() or send(something here), in your code you can use either f string or , concatenation of strings like :-

await message.channel.send(f"{message.author.display_name} is blessed by the Baltic Gods of Dairy.")

or

await message.channel.send(str(message.author.display_name)+"is blessed by Baltic gods of Dairy.")

Upvotes: 1

Siddharth Agrawal
Siddharth Agrawal

Reputation: 3156

You are trying to pass 3 arguments to the discord instead of 2. When you try concatenate strings while passing them as arguements, always use +. If you use a comma, it treats them as separate arguments and therefore gets 3 different parameters(self,author and your message) instead of 2(self and message).

async def on_message(message):
   if message.author == client.user:
       return
   if message.content.startswith('~milk'):
       await message.channel.send(message.author+ 'is blessed by the Baltic Gods of Dairy')

Upvotes: 2

mousetail
mousetail

Reputation: 8010

channel.send() takes only one argument (and the implicit self which makes it appear like 2)

You can write it like this:

await message.channel.send(f'{message.author.mention} is blessed by ...')

Upvotes: 6

Related Questions