How would run a bot in PyCharm?

Question:

Ok, so I was running my working python script/bot through Terminal using IDLE as a text editor… I realized that PyCharm would be much faster and much more efficient. Though I still do not know a lot about PyCharm. How would I do this?

from config import keys
from selenium import webdriver
import time

driver = webdriver.Chrome('./chromedriver')

def order(keys):


    driver.get(keys['destination'])

    driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[4]/ul[1]/li[2]').click()
    print('Directed to correct page...')
    driver.switch_to.window(driver.window_handles[1])
    time.sleep(1)
    driver.find_element_by_xpath('//*[@id="identifierId"]').send_keys(keys["email"])
    print('Email entered...')
    driver.find_element_by_xpath('//*[@id="identifierNext"]/span/span').click()
    print('Going to next page...')
    time.sleep(2)
    driver.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input').send_keys(keys["password"])
    print('Entered password...')
    driver.find_element_by_xpath('//*[@id="passwordNext"]/span/span').click()
    print('Going to next page...')
    time.sleep(2)


if __name__ == '__main__':
    order(keys)


input()

That is the code I am using, it works perfectly fine. I just want to use it through PyCharm. Please help!

EDIT: How would I use Selenium through PyCharm? It says that it is an unsolved reference.

EDIT: I got it to work, thank you.

Asked By: blebbybeby

||

Answers:

PyCharm won’t make your script run faster. It is just an IDE, a tool that allows you to write Python programs. It is not recommended to run it there for production. It is useful to run it there when you are programming and debugging. Use the terminal as usual to run it in production.

What you are probably experiencing is that your PyCharm is pointing to a different Pythonpath. You need to go into PyCharm settings and set your Python interpreter.

You can find out your current Python interpreter through your terminal with the command where python3 (on Windows) or which python3 (on Linux).
Note that python3 may be called python, py or py3 for you.

Answered By: Tin Nguyen

You can absolutely run your bot(s) through PyCharm. Here is a brief list of what you would need to do, to run your bot(s) in PyCharm (Assuming you already created a bot in the Discord Developer Portal):

  1. Install PyCharm and Python: If you haven’t already, download and install the latest version of PyCharm from the JetBrains website and install Python. (Won’t be going over how to install Python, there are many resources out there for that.)

  2. Create a new project: Open PyCharm and create a new project by clicking on "Create New Project" in the welcome screen.

  3. Select a Python interpreter: In the "New Project" window, select a Python interpreter that you want to use for your bot. If you don’t have one installed, click on the "Add Interpreter" button to create a new one.

  4. Install necessary packages: If your bot requires any packages or libraries, you can install them using PyCharm’s package manager. Open the "Project Interpreter" settings and click on the "+" button to add a new package.

  5. Create a Python file: In the PyCharm project window, create a new Python file by right-clicking on the project folder and selecting "New > Python File". Give the file a name and save it.

  6. Write your bot code: Write your bot code in the Python file you just created. Make sure to import any necessary packages and define any required functions.

  7. Run your bot: Once you’ve finished writing your bot code, you can run it by clicking on the green "Run" button in the toolbar at the top of the PyCharm window. This will execute your bot and display the output in the console.

  8. Debug your bot: If you encounter any errors or issues while running your bot, you can use PyCharm’s debugging tools to find and fix them. Set breakpoints in your code by clicking on the left margin of a line, then click on the "Debug" button instead of the "Run" button.

  9. Deploy your bot: Once you’re satisfied with your bot’s functionality, you can deploy it to a server or platform of your choice.

  10. Use the code: client.run(Bot Token), which you can find in the Discord Developer Portal webpage where you created your bot and its’ scope(s).

That’s it! Follow these steps to run your bot through PyCharm. (Again, this is for those who have ALREADY created their bot through the Discord Developer Portal!)

Answered By: Sir