Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 当bot加入服务器时发送消息[Discord.py]_Python_Discord.py - Fatal编程技术网

Python 当bot加入服务器时发送消息[Discord.py]

Python 当bot加入服务器时发送消息[Discord.py],python,discord.py,Python,Discord.py,我目前正在制作一个discord bot,并希望在服务器加入时在服务器的#general通道中发送一条消息,这是我到目前为止的代码 async def on_guild_join(guild): general = find(lambda x: x.name == 'general', guild.text_channels) if general and general.permissions_for(guild.me).send_messages: embe

我目前正在制作一个discord bot,并希望在服务器加入时在服务器的
#general
通道中发送一条消息,这是我到目前为止的代码

async def on_guild_join(guild):
    general = find(lambda x: x.name == 'general',  guild.text_channels)
    if general and general.permissions_for(guild.me).send_messages:
        embed=discord.Embed(title="**======== *Thanks For Adding Me!* ========**", description=f"""
        Thanks for adding me to {guild.name}!
        You can use the `--help` command to get started!
        """, color=0xd89522)
        await general.send(embed=embed)
当我运行这段代码时,什么都不会发生。我没有得到任何ERORR或输出


如果有人能帮忙,那就太棒了。谢谢

你加入工会的
是否有?当我用这个decorator测试代码时,它工作得很好

此外,如果你的机器人加入的公会没有名为“general”的频道,你可能需要一个后备通道。在
guild.text\u频道[0]
中发送消息可能更可靠,它将在第一个频道中发送消息,或者在
guild.system\u频道
中发送消息