discord.pyでイベントをテストする方法
Aug 22 2020
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のようなもの:手動でイベントをトリガーしますが、JavaScriptではなくdiscord.pyで
回答
1 KingsleyZhong Aug 23 2020 at 12:05
現在、discord.py apiにはそのようなことを行うための公式サポートはありませんが、次のように歯車でいつでもコマンドを作成できます。
@commands.command()
async def test_join(self, ctx, member: discord.Member):
await self.on_member_join(member)
技術的には、おそらく文書化されていない方法があります...
ここの131行目。文書化されていないため、追加のサポートは提供しません。