首页 > 解决方案 > 如何在我的不和谐脚本中添加真假?

问题描述

我在 python 中编写了一个打开 Firefox 的脚本,对于这个问题,它变得不和谐。

当我运行脚本时,它会转到我创建的私人频道,并且应该对我发布的消息做出反应。(这也意味着对已经有反应的每条消息做出反应。)

除了一个问题之外,它完全符合我的要求。当网站上的“反应”= True 时,它​​不会停止对消息做出反应。

我拥有我的原因while loop是它总是检查带有反应的新消息。

我不知道如何解决这个问题。完整代码如下。

(我知道这违反了不和谐的 TOS 并承担全部责任。)

#! /usr/bin/python

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time 

Email = "YourEmail"
Password = "YourPassword"

# The Function that will Auto React
def Auto_React():
    Click_Emote = driver.find_element_by_class_name('reactionInner-15NvIl').click()
    # This is where the Auto React code will go


# Open browser
driver = webdriver.Firefox()
# Go to Discord
driver.get("YourDiscordChannelLink")

# Login to Discord
email_box = driver.find_element_by_name("email")
email_box.send_keys(Email)

password_box = driver.find_element_by_name("password")
password_box.send_keys(Password)

# Pressing enter on the password box will trigger the login
driver.find_element_by_name("password").send_keys(Keys.RETURN)

# The page needs to load fully before the script can move forward
time.sleep(15)

# Bypass school email popup
bypass_school_signup = driver.find_element_by_class_name('close-hZ94c6').click()

time.sleep(5)

while True:
    Auto_React()

标签: pythondiscord

解决方案


看起来你有一个无限循环(除非我遗漏了什么?),你继续运行Auto_React它没有 break 语句,我认为你不需要 while 循环,但如果你确保在其中添加一个 break 语句所以你的代码不会无限重复!

编辑:我不确定这将如何在代码中实现,但您可以改为执行类似的操作for all messages that are already reacted to,因此基本上先获取所有已反应的消息,然后对其进行迭代并再次做出反应,这样您的代码将在您完成后终止.


推荐阅读