[英]how to make discord py bot send a message when it is invited to a server
I have a discord.py bot and I use this script to make the bot send messages to main channel when it gets invited to a server!我有一个 discord.py 机器人,我使用这个脚本让机器人在被邀请到服务器时向主频道发送消息! However this doesn't send anything to the server!
但是,这不会向服务器发送任何内容! Please Help!
请帮忙!
@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!```")
I wanted to thank everyone for replying to this post!我要感谢大家回复这篇文章! However I came up with a logic!
但是我想出了一个逻辑!
Since my bot takes admin permissions, it can post on any channel!由于我的机器人具有管理员权限,因此它可以在任何频道上发布!
Now the thing is, the bot posts the main message whenever someone says T-BOT(case sensitive)现在的问题是,只要有人说 T-BOT(区分大小写),机器人就会发布主要信息
That way, no one is ever gonna say the bot in its entirety at the same time, the bot posts its first message!这样一来,没有人会同时说出整个机器人,机器人会发布它的第一条消息!
For those wondering how to do it, you can use the on_message
discord event to make it search for the bots name!对于那些想知道如何做的人,您可以使用
on_message
discord 事件来搜索机器人名称!
I hope I helped someone in the future who is making a discord.py
bot: :-)我希望我能帮助将来制作
discord.py
机器人的人:-)
@client.event async def on_guild_join(guild): for channel in guild.text_channels: if channel.permissions_for(guild.me).send_messages: await channel.send('I will send this message when I join a server') break
I'm better at discord.js, but I'll give your discord.py problem a stab…我更擅长 discord.js,但我会给你的 discord.py 问题一个刺……
@client.event
async def on_guild_join(guild):
try:
joinchannel = guild.system_channel
# The system channel is where Discord’s join messages are sent
await joinchannel.send('Thanks for inviting me to your server!')
catch:
# if no system channel is found send to the first channel in guild
await guild.text_channels[0].send(<message>)
I last time made an answer saying that you could use the on_message, but then I came up with something 2,000 times better, Each server has a system channel and using your discord.py bot, you can find the system channel and make it send it's message there!我上次回答说你可以使用 on_message,但后来我想出了好 2000 倍的东西,每台服务器都有一个系统通道并使用你的 discord.py 机器人,你可以找到系统通道并让它在那里发送消息!
That's the best method to do it as most server owners leave a main or important channel as their system channel!这是最好的方法,因为大多数服务器所有者将主要或重要频道作为他们的系统频道!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.