Search code examples
pythondiscord.pytypeerror

Why am I getting TypeError: start_chat() missing 1 required positional argument: 'message'?


I am trying to create the main for my Discord chatbot but when trying to see if it runs I get this error:

Traceback (most recent call last):
  File "C:\Users\amjad\OneDrive\Documents\Goldsmiths\Year 3\Final Year\Project\Test4\main.py", line 87, in <module>
    DiscordChatbot.start_chat()
TypeError: start_chat() missing 1 required positional argument: 'message'

My code is as below:

  async def start_chat(self, message):
    if message.author in userinteract:
      user_response = input("Test")
      await message.channel.send(user_response)

    if message.content.startswith('$'):
            userinteract.append(message.author)

    if user_response in self.negative_responses:
      await message.channel.send(user_response)
      return
    
    self.chat(user_response)

DiscordChatbot = ChatBot()
DiscordChatbot.start_chat()

client.run("TOKEN")

The main is not fully implemented as yet as I am trying to see if my Discord bot comes online before continuing but get that error when running. How do I solve the error. Have already tried researching similar issues others were having but to no avail.


Solution

  • I think your issue lies in that you define start_chat() like this:

    async def start_chat(self, message):
    

    But at the end of your program, you call it like this:

    DiscordChatbot.start_chat()
    

    Your error means the method you're trying to run, start_chat(), needs a message in the parentheses, but it couldn't find one.

    I'm not familiar with discord.py and stuff like that (I'm very new and I've only used vanilla Python), so I can't say too much detailed stuff, but my advice would be to put a test message in there:

    DiscordChatbot.start_chat("whatever your test message is")
    

    Hope this helps! -VDizz