- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
好吧,我正在使用 Python3 开发一个 Discord 机器人,它在某种程度上可以工作,但每隔几分钟就会崩溃一次。它给了我一个错误,比如“任务已被销毁但它正在等待”。现在,我搜索了这个问题,并发现我必须摆脱我的 response = request.get(url) 并将其替换为“async with aiohttp.get(url) as response”的信息。现在,当我拥有它时,它给了我“从未等待过协程‘可用性’”。为了解决这个问题,我想我必须使用某种循环,但我对异步内容还很陌生,所以我一无所知。
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
import time
import requests
from bs4 import BeautifulSoup
import smtplib
import aiohttp
import async_timeout
async def availability():
url = "some url"
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
async with aiohttp.ClientSession().get(url, headers=headers) as response:
soup = BeautifulSoup(response.text, "lxml")
print(soup)
return soup
Client = discord.Client()
bot_prefix= "?"
client = commands.Bot(command_prefix=bot_prefix)
availible = True
@client.event
async def on_ready():
print("Bot Online!")
print("Name: {}".format(client.user.name))
print("ID: {}".format(client.user.id))
bessie = 0
waittime = 0
while True:
time.sleep(1)
if wachttijd == 0:
if ("0 available") not in str(availability()):
bessie = bessie + 1
if bessie == 3:
await client.send_message(discord.Object(id='some id'),
'<@&some channel>some text!')
print("available")
bessie = 0
waittime = 10
else:
bessie = 0
else:
wachttijd = wachttijd - 1
client.run("token")
最佳答案
然而,经过一些研究,根据我在 this stackoverflow thread 上查看的代码,我对此并不能百分百确定。这可能是因为您没有在等待 response.text。
尝试在 response.text 前面添加 await 关键字:
soup = BeautifulSoup(await response.text(), "lxml")
await asyncio.sleep(seconds)
关于Python discord bot - 从未等待过协程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47954196/
当我在 repl.it 上运行我的 discord 机器人时,出现错误。在错误中,我在下面看到了一些 HTML 代码。 CloudFlare 似乎阻止了我的机器人访问 Discord。这是什么原因造成
我计划使用 python 制作一个不和谐的机器人。 discord.py 和 discord.py[voice] 有什么区别? 最佳答案 discord.py 和 discord[voice] 之间的
我正在尝试编写一个脚本来检测用户是否以及何时将他们在 discord 上的名称从“bob”更改为“.bob”之类的名称,它会禁止此更改并将其保留为“bob”。 if (user.nickname.st
我想使用 Discord Bot 向用户发送私有(private)消息。 用户与机器人不在同一台服务器上。 如果我可以使用 author.sendMessage,我该如何初始化(查找)作者变量? 我可
我正在尝试将某人添加到特定服务器,然后通过 DM 只用不和谐 ID 表示该人。 它的工作方式是,有人在网站上使用 Discord OAuth2 登录自己,登录后他应该被添加到特定服务器,然后机器人应该
我无法弄清楚如何使用类似于 /giphy、/xivdb 等的实时“反馈”来实现斜杠命令。没有公共(public) API 吗? ?我正在使用 discord.py,但我想这对于这个问题来说并不重要。
我正在尝试使用 Discord Bot 在 discord 服务器上创建一个类别,但我无法在 Internet 上找到该方法或其他内容。我还看了“discord.js.org”。然后我认为没有任何可能
我正在为桌面创建灯,当我的麦克风在 Discord 上处于事件状态时,该灯将为绿色,当我的麦克风静音时,该灯将为红色。所以我想从不和谐中获取我的麦克风状态。但我不知道怎么做。 当我不在进行语音聊天时,
我已经看到了您允许某个角色使用命令的变体。但是,我试图实现完全相反的效果:如何禁止某个角色使用命令。 我搜索了堆栈溢出,没有找到答案,也没有在 discord.py 官方文档上找到答案。任何形式的帮助
我开发了自己的简单 discord bot(使用 discord.js)并将其部署到节点服务器。 一切正常。 现在我想为它添加更多功能。在开发过程中,我想在本地进行测试(当然)。 问题是:我可以在本地
我正在使用 Discord.js 创建一个基本的 Discord 机器人。当机器人第一次启动时,我运行 client.guilds.array()获取机器人当前订阅的所有公会的列表。我将其保存到其他程
我想为付费成员(member)提供 Discord 服务器。我想我可以让他们通过 Stripe 付款,向他们发送付款邀请,然后定期运行 Python 脚本,该脚本检查我的所有 Discord 成员是否
我试图向我的机器人添加一些新功能,但它最终没有工作,所以我删除了新代码,现在它不会响应任何命令。它仍然在线,但正如我之前所说,它完全没有响应。我已经查看了代码,但找不到问题。我对编码机器人还是个新手,
我正在编写一个建议机器人,它应该将玩家的建议发送到我服务器中的建议 channel ,并在建议 channel 中用一些表情符号使用react。 问题是使用“消息”作为消息参数会对发送到触发代码的消息
我想创建一个清除命令,如果 example .clear @user#0000 100 它将清除@user#0000 发送的最后 100 条消息。这是我的代码: @commands.comma
所以,我想为我的机器人创建一个命令,它可以从给定的消息 ID 中获取所有反应并将这三个类别存储到数组中,对于每个 react : react 的名称(例如:smile:) 使用react的用户(例如
我正在尝试在 discord.js 上制作一个简单的右舷系统,删除消息部分让我很困惑。目前,如果一条消息获得星号,则会在右舷 channel 创建一个嵌入,而且至关重要的是,页脚是原始消息的 ID。我
我最近启动了一个新的 discord.js 机器人,但出现“无效 token ”错误。这不可能是因为 async 功能,因为我只启动了机器人并且我有 0 个命令,上次发生这种情况是当我试图在 hero
我正在尝试向我的机器人添加一条命令,该命令会回复用户邀请到服务器的总人数 我的代码: if message.content.startswith('!invites'): totalInvit
我在一些服务器/公会中添加了一个 Discord 机器人。我可以使用此处提供的资源获得特定公会: https://discord.com/developers/docs/resources/guild
我是一名优秀的程序员,十分优秀!