【发布时间】:2021-07-23 00:22:27
【问题描述】:
我有一个 discord.py 机器人,我使用这个脚本让机器人在被邀请到服务器时向主频道发送消息! 但是,这不会向服务器发送任何内容!请帮忙!
@client.event
async def on_guild_join(guild):
print("NEW SERVER WAS JOINED!")
general = find(lambda x: x.name == 'general', guild.text_channels)
if general and general.permissions_for(guild.me).send_messages:
await general.send(f"""
████████╗░░░░░░██████╗░░█████╗░████████╗
╚══██╔══╝░░░░░░██╔══██╗██╔══██╗╚══██╔══╝
░░░██║░░░█████╗██████╦╝██║░░██║░░░██║░░░
░░░██║░░░╚════╝██╔══██╗██║░░██║░░░██║░░░
░░░██║░░░░░░░░░██████╦╝╚█████╔╝░░░██║░░░
░░░╚═╝░░░░░░░░░╚═════╝░░╚════╝░░░░╚═╝░░░
```Thanks For Inviting the bot!
Made with <3 by TOG6#6666 with Tons of help from the TOG6 community!```
***Server Invite:*** https://discord.gg/vSxuAbq""")
await general.send(f"``` Type $help to view all commands!```")
【问题讨论】:
-
你试过没有
if吗?你检查过你在general里有什么吗?也许它有一些与你预期不同的东西,这使得if永远不会被执行。 -
@furas 对不起,我没有正确地提出我的问题,比如我如何让它将该消息发送到服务器的主频道,服务器不需要通用频道跨度>
-
您可以尝试打印
general变量吗? -
你在bot加入后尝试将消息发送到主频道,频道不必命名为general但它应该是主频道对吧?如果是这样,机器人应该如何知道主要渠道是什么? ???除非您可以让机器人检查每个频道的消息最多的频道,但这可能需要很长时间才能发送消息,并且可能会使机器人慢一点,这是不好的。主要频道更有可能被命名为一般或主要频道,所以也许您可以寻找那些或做其他。
标签: python python-3.x discord.py discord.py-rewrite