- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我到处搜索这个问题,但找不到答案。
我刚刚开始学习 discord.py,之前的 python 知识很少,如果这个问题看起来很简单,我很抱歉,我只使用 YouTube 教程就做了大约 12 个小时。
所以我的问题是如何在齿轮内部设置移动状态?我不断收到一条错误消息,提示“AttributeError:模块‘discord.ext.commands’没有属性‘event’”。
代码是
import discord
import os
from discord.ext import commands
from itertools import cycle
status = cycle(['First status', 'Second status', 'Third status'])
class status(commands.Cog):
def __init__(self, client):
self.client = client
@tasks.loop(seconds=3)
async def change_status():
await commands.change_presence(activity=discord.Game(next(status)))
@commands.event
async def on_ready():
change_status.start()
print('Bot ready')
def setup(client):
client.add_cog(status(client))
在此先感谢您的帮助!
最佳答案
经过相当多的研究,我已经能够修复您遇到的错误。但是,我一直无法真正改变状态;这可能是因为我没有正确使用 change_presence()
方法。尽管如此,我至少可以帮助您消除错误,您可以从那里开始。下面是我在您的代码中指出的先前错误的合并,以及将消除错误消息的代码。
import discord
import os
from discord.ext import commands, tasks
from itertools import cycle
class status(commands.Cog):
def __init__(self, client):
self.client = client
self.status = cycle(['First status', 'Second status', 'Third status'])
@tasks.loop(seconds=3.0)
async def change_status(self):
print('Changing status')
await self.client.change_presence(activity=discord.Game(next(self.status)))
@commands.Cog.listener()
async def on_ready(self):
self.change_status.start()
def setup(client):
client.add_cog(status(client))
导致错误的原因是 @commands.event
不存在。相反,您必须使用 @commands.Cog.listener()
,这就是错误显示 'discord.ext.commands' has no attribute 'event'
的原因.我找到了一个 reddit forum谈论您遇到的相同问题,并且该人实际上能够解决它,所以我建议您仔细阅读并亲自尝试。我将删除我的旧答案,因为这个包含我指出的所有内容。另外,如果您接受这个答案,我将不胜感激,因为它确实消除了您询问的错误。
关于python - cog 中的 discord.py 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66095007/
随着我的机器人越来越大,我正在尝试实现齿轮,但是我遇到了一个问题。我已设置并准备好整个代码,但由于某些奇怪的原因,我不断收到此错误: Traceback (most recent call l
是否可以为每个齿轮设置前缀? 例如,带有管理命令的 Cog 具有前缀 pa!,而一些有趣命令的 cog 具有前缀 pf!。 不使用 on_message。 编辑:我想我必须更详细地介绍: 我的 ser
有谁知道 Pharo 和 Squeak 的 Cog VM 是否能够使用如下访问器优化简单的间接变量访问: SomeClass>>someProperty ^ someProperty Some
我写了一个使用 cogs 的 discord 机器人。这是我在每个扩展/齿轮中加载的代码: import discord import os from discord.ext import comma
我已经设置了一个 discord.py cog,可以使用了。有一个问题,如何为命令设置别名?我会在下面给你我的代码,看看我还需要做什么: # Imports from discord.ext impo
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭去年。 Improve th
我的代码: import discord from discord.ext import commands import re import os class Help2(commands.Cog):
我们正在使用和添加/删除某些 js 事件的 fa-spin。在 3x 下很容易看到的问题是齿轮不围绕固定轴旋转。我怀疑这是因为图标本身 (SVG) 被 Chrome 报告为 42 x 49 像素,即使
我到处搜索这个问题,但找不到答案。 我刚刚开始学习 discord.py,之前的 python 知识很少,如果这个问题看起来很简单,我很抱歉,我只使用 YouTube 教程就做了大约 12 个小时。
我有一个相当大的 Discord 机器人。它有超过 1000 行代码。当我在 Youtube 和这里研究如何做到这一点时,似乎没有任何效果。我想知道是否有人可以解释如何正确使用齿轮,可能是照片示例
我想让它尽可能原生。所以我需要一种获取系统图标的可能性。 我唯一能找到的是如何获取对话框图标,例如SWT.ICON_ERROR等。是否有机会获得其他系统图标,如打开、保存、复制等? 最佳答案 目前 S
@commands.Cog.listener() async def on_message(self, message): channel = self.client.get_channel(
根据他们的指南,这太奇怪了 here ,我添加了一个带有 glyphicon glyphicon-cog 的跨度......但是,当加载我的页面时,它实际上显示了信封 - 这是 glyphicon g
如标题所述:我想创建一个 3D 齿轮,它有 10 个齿,围绕其中心旋转(就像齿轮一样)。齿轮有方形齿,为了简单起见,齿间有平坦的侧面 - 这个齿轮上没有曲线。 齿轮一侧的可视化效果。请注意,角度并非
我对 Unix/Linux 系统很陌生,我在我的 Windows 机器上编写了这个程序,所以它工作得很好,我查看了 this并且很困惑。 这是我的全局代码: COGS = [path.split("\
最近我的 bot 越来越大,我花时间重写代码以使其与 Discord Py 的 cogs 系统一起工作 我已经正确调整了所有代码,但是我停止工作的所有 on_message 事件都没有抛出任何类型的错
我正在尝试使用 VMware 和主机 macOS 在 Ubuntu 上运行 WPE WebKit,但我收到以下错误消息: ➜ flatpak run org.wpe.Cog -P fdo http:
当我尝试加载位于模块文件夹中的配置扩展时,我这样做,但它不起作用: bot.load_extension("modules/config") 当我将其移动到主 python 文件所在的同一文件夹中时,
我在 bot.py 文件中定义了一个名为“前缀”的变量,该变量可以在稍后的命令中使用,例如显示给用户。它的目的是简单地存储机器人前缀。但是,我不知道如何在其他 cog 文件中使用此变量。 bot.py
我正在尝试在 Cog 中集成一个基本的 aiohttp 网络服务器(使用 discord-py 重写)。我正在为齿轮使用以下代码: from aiohttp import web import dis
我是一名优秀的程序员,十分优秀!