我有此代码:
class member_greeting(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_guild_join(self):
for guild in self.bot.guilds:
await guild.system_channel.send("I'm ready to go!")
def setup(bot):
bot.add_cog(member_greeting(bot))
不将消息发送到系统消息传递通道 如何正确书写?
答案 0 :(得分:1)
on_guild_join
事件具有一个guild
参数:
class member_greeting(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_guild_join(self, guild):
await guild.system_channel.send("I'm ready to go!")
def setup(bot):
bot.add_cog(member_greeting(bot))
如果您希望机器人在加入新公会时在它所在的每台服务器中发送一条消息,我相信您必须使用async for guild in self.bot.guilds:
而不是for guild in self.bot.guilds
:
class member_greeting(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_guild_join(self):
async for guild in self.bot.guilds:
await guild.system_channel.send("I'm ready to go!")
def setup(bot):
bot.add_cog(member_greeting(bot))