作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道是否可以使用@bot.event
在 discord.py 的齿轮中。我试过做
@self.bot.event
async def on_member_join(self, ctx, member):
channel = discord.utils.get(member.guild.channels, name='general')
await channel.send("hello")
NameError: name 'self' is not defined
最佳答案
要从 new-style cog 注册事件,您必须使用 commands.Cog.listener
装饰器。下面是转换为新样式的mental 示例:
from discord.ext import commands
class Events(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_ready(self):
print('Ready!')
print('Logged in as ---->', self.bot.user)
print('ID:', self.bot.user.id)
@commands.Cog.listener()
async def on_message(self, message):
print(message)
def setup(bot):
bot.add_cog(Events(bot))
关于python-3.x - 齿轮 discord.py 中的 @bot.event,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48038953/
所以我在 OpenShift 上有两个免费装备。一个是带有 MySql 5.7 的 PHP,来自: https://github.com/icflorescu/openshift-cartridge-
我想制作一个 404 页面,其中有几个齿轮需要旋转一秒钟左右,然后慢慢停止旋转,最后完全静止不动。在我看来,这是一个很好的效果,让我的访客知道出了点问题(机器/齿轮停止工作)。 我想用纯 css 来完
我想知道是否可以使用@bot.event 在 discord.py 的齿轮中。我试过做 @self.bot.event async def on_member_join(self, ctx, memb
我是一名优秀的程序员,十分优秀!