This is a script that sends randomly generated sentences into a discord chat. But it occasionally runs into the error: UnicodeDecodeError: 'ascii' codec cant decode byte 0xef in position 2141: ordinal not in range(128)
How would I solve this error?
Code:
import asyncio
import random
import discord.ext.commands
import markovify
import nltk
import re
with open("/root/sample.txt") as f:
text = f.read()
class POSifiedText(markovify.Text):
def word_split(self, sentence):
words = re.split(self.word_split_pattern, sentence)
words = [w for w in words if len(w) > 0]
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
text_model = POSifiedText(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('286342556600762369')
messages = [(text_model.make_sentence(tries=33, max_overlap_total=10, default_max_overlap_ratio=0.5))]
await client.send_message(channel, random.choice(messages))
await asyncio.sleep(15)
client.loop.create_task(background_loop())
client.run("MjY2NjkwNDY4MjI4NzU5NTU4.C5jcdw.WFfBTUmAY7UcrwKTwYFJ9_bFHjI")
The error is occurring on line 9.