如何读取.txt文件中的一行文本

时间:2017-09-29 02:06:42

标签: python discord

我想知道如何将它转到哪里,而不是为随机选择消息输入所有内容,而不是如何使用.txt文件。这是我的代码:

   import discord
   from discord.ext.commands import Bot
   from discord.ext import commands
   import asyncio
   import time
   import random
   import ctx
   import timeit
   import traceback
   import logging

   bot_prefix = "!"
   bot = commands.Bot(command_prefix=bot_prefix)


   @bot.event
   async def on_ready():
   print("Bot Online!")
   print("Name: {}".format(bot.user.name))
   print("ID: {}".format(bot.user.id))

@bot.command(pass_context = True)
@commands.cooldown(1, 30, commands.BucketType.user)
async def getalt(ctx):
    msg = ["danielmarmeloreis@gmail.com:slime1234", "danielkrock9@yahoo.com:sagaraghi123", "danielemilerevah@gmail.com:truffles101", "danieldiazlauraagudo@hotmail.com:manolo39", "e1verity@yahoo.com:Blessed1", "daniellachner64@gmail.com:london2004", "dyllonng@gmail.com:t0403752e", "danielgrolik@web.de:26101999", "danielspaniel6011@gmail.com:coolboy12", "dyllindsay@live.com:Spiderman23", "eac141099@hotmail.com:Megustaelpan", "eafut13playgood@hotmail.de:sinanovic1", "dyllynnbell@gmail.com:mdb74523", "danielvtotino@rogers.com:dvt2002", "danilklin17@gmail.com:Vfvjxrf1979", "danieltavazzi@alice.it:tavazzi96", "danilofleischer@web.de:FcBayern69", "danielgibert@hotmail.com:costurera01", "danielkozak51@gmail.com:Jetsfan7", "eagle3_2003@yahoo.com:brophy", "eab202303986@eabdf.br:GDF2005", "danijano1999@hotmail.cl:dact1999", "eaglenebulangc6611@gmail.com:Robotics", "danielsimovski23@gmail.com:kikoman23", "dyllanweich@outlook.com:djdyllan1", "danielarendt282@gmail.com:Lego1234", "danielbrodie04@gmail.com:nirvanna2", "daniele.vavala@gmail.com:milo123456", "e.duckworth11@gmail.com:AgentP00", "danielfelipe142009@hotmail.com:samuel1254", "danielkautz139@googlemail.com:Jagd123", "e_wetzl@yahoo.de:yolo1234", "danielograbek@gmail.com:danielo2000", "e3zofficiel@gmail.com:nintendo64", "e.dundon95@gmail.com:Eoinqzell95", "e.boy612@gmail.com:angels612", "e99wright@gmail.com:Monkey99", "dynodriver52@gmail.com:school09", "e319707@gmail.com:ilovetacos11"]
    await bot.send_message(ctx.message.author, random.choice(msg))
    await bot.send_message(ctx.message.channel, "Alt Has Been Seen To Your DMs")

如果我有电子邮件和密码,我想使用.txt文件,而不是我必须输入每一个。正如您所看到的,每个命令用法只有一封电子邮件并传递组合,因此在我的txt文件中,我会在新行上使用每个组合。

1 个答案:

答案 0 :(得分:0)

file read and write

我在理解您的问题时遇到了一些麻烦,但如果您只想阅读电子邮件文件中的行,请将其存储在列表中:

    emailFile = open("emailFile.txt", "r")
    emails = []
    for email in emailFile:
        emails.append(email)

预计您的emailFile.txt每行都有一个单独的电子邮件