我是python中级用户和经验丰富的Selenium用户,并希望将这些技能与我对新的discord.py重写的一点了解结合起来。我创建的代码无头运行selenium-它导航到一个网站,填写表格,然后截屏。我遇到的问题是discord.py的channel.send文件功能。这是我的代码-
async def on_message(message):
id = client.get_guild(guildcode)
valid_users = ["discord#tag"]
if str(message.author) in valid_users:
if message.content.find("!gen") != -1:
await message.channel.send("Generating coupon now...")
driver.get('example.com')
elem = driver.find_element_by_name("CN1")
elem.click()
elem.clear()
surveyCode = '36901999912012386'
elem.send_keys(surveyCode)
clicksDone = 0
while int(clicksDone) < 25:
elem = driver.find_element_by_id('NextButton')
elem.click()
clicksDone = clicksDone + int('1')
if clicksDone == 25:
driver.get_screenshot_as_file('capture.png')
await message.channel.send('Generated!')
await channel.send(file=discord.File('capture.png'))
机器人正确填写了调查问卷,输出它已生成优惠券,但未能发送新拍摄的屏幕截图-capture.png。这是我遇到的错误-
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\hp\PycharmProjects\telldunkin\venv\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "C:/Users/hp/PycharmProjects/telldunkin/discorddonut.py", line 37, in on_message
await channel.send(file=discord.File('capture.png'))
NameError: name 'channel' is not defined
当我摆脱发送文件代码时,不会出现错误。在此先感谢您的帮助。
在您提供的代码段中,我没有看到channel
定义,我想这是之前定义的列表。您的问题是您在执行channel.send
,而不是我想的message.channel.send
。
编辑:我读错了,python说第channel.send(message, image)
行有错误,但是该行不在您的代码段中。