Events 如何在discord.py中测试事件
让我们说一下会员加入活动Events 如何在discord.py中测试事件,events,event-handling,discord,discord.py,Events,Event Handling,Discord,Discord.py,让我们说一下会员加入活动 @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_c
@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.py中不在JavaScript中的内容目前discord.py api中没有官方支持这样做,但您始终可以在cog中发出如下命令:
@commands.command()
async def test_join(self, ctx, member: discord.Member):
await self.on_member_join(member)
从技术上讲,有一种方法可能没有记录在案
第131行输入。我不会提供额外的支持,因为它没有文档记录。您能进一步解释一下您想要实现的目标吗?这没有多大意义。有(Discord.js:手动触发事件)[Discord.py中有相同的选项吗?