import discord
import asyncio
from tqdm import tqdm
from sys import argv

script, fileName = argv
client = discord.Client()

@client.event
async def on_ready():
    print('Connection successful.')
    print('ID: ' + client.user.id)
    print('-----')
    target = open(fileName, 'w')
    print(fileName, 'has been opened.')

    messageCount = 0
    channel = discord.Object(id='107634811132231680')

    print('Scraping messages...')
    with tqdm(leave=True,unit='messages') as scraped:
        async for msg in client.logs_from(channel, 10000000000):
            line = "{} - {}: {}".format(msg.timestamp,msg.author.name, msg.content)
            line = line.encode('utf-8')
            toWrite = "{}".format(line)
            target.write(toWrite)
            target.write("\n")
            #messageCount += 1
            #print(messageCount)
            #print(msg.author,msg.content)
            scraped.update(1)
    print('-----')
    print('Scraping complete.')


#----------------------------

client.run('email', 'password')

import discord
import asyncio
from tqdm import tqdm
#from sys import argv
import argparse

parser = argparse.ArgumentParser(description='Discord channel scraper')
requiredNamed = parser.add_argument_group('Required arguments:')
requiredNamed.add_argument('-c', '--channel', type=str, help='Channel to scrape. Requires the channel ID.', required=True)
requiredNamed.add_argument('-o', '--output', type=str, help='Output file in form *.txt. Will be stored in the same directory.', required=True)

args = parser.parse_args()
print(args.channel)
print(args.output)

#script, fileName = argv
client = discord.Client()

@client.event
async def on_ready():
    print('Connection successful.')
    print('ID: ' + client.user.id)
    print('-----')
    target = open(args.output, 'w')
    print(args.output, 'has been opened.')

    messageCount = 0
    channel = discord.Object(id=args.channel)

    print('Scraping messages...')
    with tqdm(leave=True,unit='messages') as scraped:
        async for msg in client.logs_from(channel, 10000000000):
            line = "{} - {}: {}".format(msg.timestamp,msg.author.name, msg.content)
            line = line.encode('utf-8')
            toWrite = "{}".format(line)
            target.write(toWrite)
            target.write("\n")
            messageCount += 1
            #print(messageCount)
            #print(msg.author,msg.content)
            scraped.update(1)
    print('-----')
    print('Scraping complete.')


#----------------------------

client.run('email', 'password')

Change to use argparse to parse arguments
Change to use argparse to parse arguments

  import discord
  import asyncio
  from tqdm import tqdm
- from sys import argv
+ #from sys import argv
+ import argparse
  
+ parser = argparse.ArgumentParser(description='Discord channel scraper')
+ requiredNamed = parser.add_argument_group('Required arguments:')
+ requiredNamed.add_argument('-c', '--channel', type=str, help='Channel to scrape. Requires the channel ID.', required=True)
+ requiredNamed.add_argument('-o', '--output', type=str, help='Output file in form *.txt. Will be stored in the same directory.', required=True)
+ 
+ args = parser.parse_args()
+ print(args.channel)
+ print(args.output)
+ 
- script, fileName = argv
+ #script, fileName = argv
  client = discord.Client()
  
  @client.event
  async def on_ready():
      print('Connection successful.')
      print('ID: ' + client.user.id)
      print('-----')
-     target = open(fileName, 'w')
+     target = open(args.output, 'w')
-     print(fileName, 'has been opened.')
+     print(args.output, 'has been opened.')
  
      messageCount = 0
-     channel = discord.Object(id='107634811132231680')
+     channel = discord.Object(id=args.channel)
  
      print('Scraping messages...')
      with tqdm(leave=True,unit='messages') as scraped:
          async for msg in client.logs_from(channel, 10000000000):
              line = "{} - {}: {}".format(msg.timestamp,msg.author.name, msg.content)
              line = line.encode('utf-8')
              toWrite = "{}".format(line)
              target.write(toWrite)
              target.write("\n")
-             #messageCount += 1
+             messageCount += 1
              #print(messageCount)
              #print(msg.author,msg.content)
              scraped.update(1)
      print('-----')
      print('Scraping complete.')
  
  
  #----------------------------
  
  client.run('email', 'password')
  
Change to use argparse to parse arguments
## Code Before:
import discord
import asyncio
from tqdm import tqdm
from sys import argv

script, fileName = argv
client = discord.Client()

@client.event
async def on_ready():
    print('Connection successful.')
    print('ID: ' + client.user.id)
    print('-----')
    target = open(fileName, 'w')
    print(fileName, 'has been opened.')

    messageCount = 0
    channel = discord.Object(id='107634811132231680')

    print('Scraping messages...')
    with tqdm(leave=True,unit='messages') as scraped:
        async for msg in client.logs_from(channel, 10000000000):
            line = "{} - {}: {}".format(msg.timestamp,msg.author.name, msg.content)
            line = line.encode('utf-8')
            toWrite = "{}".format(line)
            target.write(toWrite)
            target.write("\n")
            #messageCount += 1
            #print(messageCount)
            #print(msg.author,msg.content)
            scraped.update(1)
    print('-----')
    print('Scraping complete.')


#----------------------------

client.run('email', 'password')

## Instruction:
Change to use argparse to parse arguments
## Code After:
import discord
import asyncio
from tqdm import tqdm
#from sys import argv
import argparse

parser = argparse.ArgumentParser(description='Discord channel scraper')
requiredNamed = parser.add_argument_group('Required arguments:')
requiredNamed.add_argument('-c', '--channel', type=str, help='Channel to scrape. Requires the channel ID.', required=True)
requiredNamed.add_argument('-o', '--output', type=str, help='Output file in form *.txt. Will be stored in the same directory.', required=True)

args = parser.parse_args()
print(args.channel)
print(args.output)

#script, fileName = argv
client = discord.Client()

@client.event
async def on_ready():
    print('Connection successful.')
    print('ID: ' + client.user.id)
    print('-----')
    target = open(args.output, 'w')
    print(args.output, 'has been opened.')

    messageCount = 0
    channel = discord.Object(id=args.channel)

    print('Scraping messages...')
    with tqdm(leave=True,unit='messages') as scraped:
        async for msg in client.logs_from(channel, 10000000000):
            line = "{} - {}: {}".format(msg.timestamp,msg.author.name, msg.content)
            line = line.encode('utf-8')
            toWrite = "{}".format(line)
            target.write(toWrite)
            target.write("\n")
            messageCount += 1
            #print(messageCount)
            #print(msg.author,msg.content)
            scraped.update(1)
    print('-----')
    print('Scraping complete.')


#----------------------------

client.run('email', 'password')
