【发布时间】:2020-12-11 15:11:57
【问题描述】:
让我们说 on_member_join 事件
@commands.Cog.listener()
async def on_member_join(self, member):
# On member joins we find a channel called general and if it exists,
# send an embed welcoming them to our guild
channel = discord.utils.get(member.guild.text_channels, name="welcome")
if channel:
embed = discord.Embed(
description="Welcome to our guild!",
color=random.choice(self.bot.color_list),
)
embed.set_thumbnail(url=member.avatar_url)
embed.set_author(name=member.name, icon_url=member.avatar_url)
embed.set_footer(text=member.guild, icon_url=member.guild.icon_url)
embed.timestamp = datetime.datetime.utcnow()
await channel.send(embed=embed)
这是我的事件(我知道它有效)我如何以任何方式测试它以执行命令以发出事件(而不是通过添加和删除某人手动)?
[类似于 .emit on_member_join @user 其中 arg1 是事件,如果需要 arg2 是提及或频道 ID]
有什么命令吗?
类似于 Discord.js: Manually triggering events 但在 discord.py 中而不是在 JavaScript 中
【问题讨论】:
-
你能进一步解释你想要达到的目标吗?这没有多大意义。
-
好吧(Discord.js:手动触发事件)[stackoverflow.com/questions/57478980/… discord.py 中是否有选项可以做同样的事情?
标签: events event-handling discord discord.py