Iファイルを読み取り、そのファイルからランダムに1行を選択し、DMを介してdiscordボットとして送信します。しかし、txtファイルの特定のセクションを読むには、セクションの開始と終了の文字が必要です。 例:、 こんにちは 、特定の文字がある場所に基づいてtxtファイルを読み取る方法
これは私はそれがランダムな行を読み込み、DMを通してそれを送信し使用しているコードです:
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 = emails
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.")
は、ここで私のリビジョンです:
emailFile = open("C:/Users/jacob/Downloads/Uplay_Formatted.txt", "r",
encoding="utf16").read()
parse = False
email = []
for com in emailFile.split('\n'):
if com.startswith(',Credentials'):
parse = True
elif com.startswith(',Credentials'):
parse = False
if parse:
email.append(com)
@bot.command(pass_context = True)
@commands.cooldown(1, 30, commands.BucketType.user)
@commands.has_any_role("| Premium |")
async def spotifypremium(ctx):
msg = email
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.")
コメントは議論の延長ではありません。この会話は[チャットに移動]されています(http://chat.stackoverflow.com/rooms/156401/discussion-on-answer-by-felasniper-how-to-read-a-txt-file-based-on- where-a-speci)があります。 – Andy