0

I have this code:

emailFile = open("C:/Users/jacob/Downloads/Spotify_premiums.txt", "r")
emails = []
for email in emailFile:
    emails.append(email)

@bot.command(pass_context = True)
@commands.cooldown(1, 30, commands.BucketType.user)
@commands.has_any_role("| Premium |")
async def spotifypremium(ctx):
    msg = emailFile
    await bot.send_message(ctx.message.author, random.choice(msg))
    await bot.send_message(ctx.message.channel, "Alt Has Been Seen To Your DMs")
    await bot.purge_from(ctx.message.channel, limit=2)
    await bot.send_message(ctx.message.author, "Please Wait 30 Seconds Before Using This Command Again. If you do not wait the full time then you won't be sent an alt.")

I am getting the error TypeError: object of type '_io.TextIOWrapper' has no len()... I am attempting to use a text file instead of having a lengthy msg variable. I want the bot to use a random line from the text file and send it through DM.

  • 1
    Why are you passing `emailFile` to `random.choice()`? Perhaps you wanted to pass `emails` instead? – Martijn Pieters Sep 29 '17 at 11:37
  • @MartijnPieters I had made a question previous to this and it was asking how to read a text file to use it in my statement and that’s how I was told to do it.... I am trying to get it to take a random line of the text file and send it through dms –  Sep 29 '17 at 12:21

0 Answers0