2017-09-29 11 views
0

代わりに.txtファイルを使用する方法を無作為に選択するメッセージのすべてを入力する代わりに、どのようにしたらよいかを知りたいと思っています。ここに私のコードはあります:.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 = ["[email protected]:slime1234", "[email protected]:sagaraghi123", "[email protected]:truffles101", "[email protected]:manolo39", "[email protected]:Blessed1", "[email protected]:london2004", "[email protected]:t0403752e", "[email protected]:26101999", "[email protected]:coolboy12", "[email protected]:Spiderman23", "[email protected]:Megustaelpan", "[email protected]:sinanovic1", "[email protected]:mdb74523", "[email protected]:dvt2002", "[email protected]:Vfvjxrf1979", "[email protected]:tavazzi96", "[email protected]:FcBayern69", "[email protected]:costurera01", "[email protected]:Jetsfan7", "[email protected]:brophy", "[email protected]:GDF2005", "[email protected]:dact1999", "[email protected]:Robotics", "[email protected]:kikoman23", "[email protected]:djdyllan1", "[email protected]:Lego1234", "[email protected]:nirvanna2", "[email protected]:milo123456", "[email protected]:AgentP00", "[email protected]:samuel1254", "[email protected]:Jagd123", "[email protected]:yolo1234", "[email protected]:danielo2000", "[email protected]:nintendo64", "[email protected]:Eoinqzell95", "[email protected]:angels612", "[email protected]:Monkey99", "[email protected]:school09", "[email protected]: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ファイルを使用したいと思います。そしてあなたが見ることができるように、1つの電子メールがあり、コマンドの使用ごとにコンボを渡すので、私のtxtファイルでは、私は新しい行にすべてのコンボを持っています。

+0

JSONファイルに資格情報を保存しますか? –

+0

あなたのコードで字下げの問題を修正し、 'msg'の各文字列を改行に入れて、人々がそれをすべて見るためにスクロールする必要がないようにしてください。 – ROAR

+0

@ROARあなたはいくつの行があるのか​​分からないと思います...あなたの返信に感謝しますが、その改訂は不要です –

答えて

0

file read and write

私はあなたの問題を理解することはほとんどトラブルを抱えていますが、自分のメールファイルから行を読み込むしたいしている場合、リストに保存しています:

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

このあなたのemailFile.txtには、1行に1つのメールがあります。

+0

同様のメカニックス/ロジック構造を使用して、このファイルまたは別のファイルに書き込むことができます –

+0

申し訳ありませんが、私はここではあまり明確ではありません。これは初めてです...私はボットに私のデスクトップにあるテキストファイルの電子メールのパスワードからのランダムメッセージ –

+0

私はそこにある長いmsg変数ではなく、情報のリストでテキストファイルを使用したい –

関連する問題