简体   繁体   English

如何让 discord py bot 在被邀请到服务器时发送消息

[英]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.

相关问题 不和谐.py | 当我发送特定消息时,如何制作一个提供角色的不和谐机器人? - Discord.py | How to make a discord bot that gives roles when i send a specific message? 当机器人加入服务器时发送消息 [Discord.py] - Send message when bot joins server [Discord.py] Discord.py 如何让机器人向特定频道发送消息 - Discord.py How to make a bot send message to a specific channel Discord.py-如何让机器人在被 ping 时发送消息,但在回复时不发送消息 - Discord.py- How to make bot send a message when pinged but not when replied to 如何使 discord.py bot 发送到它被调用的服务器? - How to make discord.py bot send to the server it's called in? Discord.py- ping 时如何将 bot 消息设置为服务器前缀? - Discord.py- How to make a bot message the server prefix when its pinged? Discord.py bot - 如果语句为真,则向 discord 服务器发送消息 - Discord.py bot - Send message to discord server if statement is true discord.py:如何让邀请/添加机器人到他的服务器的用户? [解决方案] - discord.py: How to get the user who invited/added the bot to his server? [solution] Discord.py bot - 如何让机器人在 DM 中向我发送用户的消息? - Discord.py bot - How to make a bot send user's message to me in DM? 如何使我的discord.py重写机器人向消息作者发送私人消息 - How to make my discord.py rewrite bot send a Private Message to the message author
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM