【发布时间】:2021-05-15 20:35:21
【问题描述】:
我试图让我的代码检查两个字符串在列表中是否相等。如果它们不相等,则应直接向不和谐客户端发送消息。如果是,它应该继续使用该功能。我收到一条错误消息,提示“NoneType”对象没有属性发送。如果我复制这些行:
channel = bot.get_channel(123456789)
await channel.send("Message")
只需删除 await 并将其粘贴到函数之外,我不会收到错误消息。我假设我的全局声明有问题,但我不确定。有人可以帮忙吗?
bot = commands.Bot(command_prefix='!')
# instantiating discord client
token = "redacted"
client = discord.Client()
@tasks.loop(seconds=5.0)
async def scrape():
global linksAndTitles
global pbe_titles
global currPatch
global allTitles
global recentPatches
global currTemp
temp = []
URL = "redacted"
page = urlopen(URL)
soup = BeautifulSoup(page, 'html.parser')
pbe_titles = soup.find_all('redacted', attrs={'redacted': 'redacted'})
for tags in pbe_titles:
temp.append(tags.text.strip())
tempCurr = '\n'.join(str(line) for line in temp[:1])
if tempCurr != currTemp:
channel = bot.get_channel(123456789)
await channel.send("Message")
正是最后两行给我抛出了错误。
【问题讨论】:
标签: python function discord discord.py