0

I'm making a discord bot that spurts out randomly generated sentences into the chat every few seconds. Im trying to use the nltk module to make the sentence structure a little better, but I'm caught up on an error and cant figure it out.(I'm newish to python and have been learning everything i need to know as i go along.)

Error:

  File "/root/PycharmProjects/untitled/Loop.py", line 29, in background_loop
    messages = [(POSifiedText.make_sentence(tries=8, max_overlap_total=14, default_max_overlap_ratio=5.6,))]
TypeError: make_sentence() missing 1 required positional argument: 'self'

Code:

    import asyncio
    import random
    import discord.ext.commands
    import markovify
    import nltk
    import re

    class POSifiedText(markovify.Text):
        def word_split(self, sentence):
            words = re.split(self.word_split_pattern , sentence )
            words = ["::".join(tag) for tag in nltk.pos_tag ( words )]
            return words

        def word_join(self, words):
            sentence = " ".join(word.split("::")[0] for word in words )
            return sentence

    with open("/root/sample.txt") as f:
        text = f.read()


    text_model = (markovify.Text(text, state_size=1))

    client = discord.Client()
    async def background_loop():
        await client.wait_until_ready()
        while not client.is_closed:
            channel = client.get_channel('ChannelIdHere')
            messages = [(POSifiedText.make_sentence(tries=8, max_overlap_total=14, default_max_overlap_ratio=5.6,))]
            await client.send_message(channel, random.choice(messages))
            await asyncio.sleep(10)

    client.loop.create_task(background_loop())
    client.run("TokenHere")
Museman
  • 7
  • 1
  • 6

1 Answers1

1

You need to call make_sentence on an instance of the Text object.

text_model.make_sentence(...)

I think you also want to use your custom class like so:

text_model = POSifiedText(text, state_size=1)
Max Weinzierl
  • 1,231
  • 10
  • 13