Ok, so I want to know how to make a bot send a message to the user who boosted the server. So like for instance somebody boosted the server and the bot sent them a message. The following is an example of what I'm thinking.
Client.event()
async def on_boost():
booster.send(message)
#client.event
async def on_message(message):
if "MessageType.premium_guild" in str(message.type):
await message.channel.send("Thanks for server boost")
use this
I left a short message because I am not good at English. I'm sorry if
I offended you. If you leave a comment, I'll answer it.
Normally when someone boosts, a message is put into the discord service channel of a guild. I assume that you can have an if statement in an on_message event that will trigger if a message is in the format of an boost message + it's author is either the server or None
Related
I am hosting my own local bot, however it seems as 'on_command' does not get invoked when other bots in my server are used. Could this be security restrictions? Is there any way to change this or log other bot commands?
#bot.event
async def on_command(ctx):
print(ctx)
Bot is functioning as expected - nothing is printed when a different bot runs a command.
There's no such event that can detect if other bots' commands are being used. The only one that can do something like that is on_message, and you also have to code the checks yourself.
The on_command() event does exist in discord.py, but it is only invoked when a command is used on your bot.
One way to check if a message is sent by a bot is to use the on_message() event, like this:
#bot.event
async def on_message(message):
if message.author.bot:
# Message is sent by a bot!
# ...
The message.author.bot checks if the message's author is a bot.
I have a bot that currently does nothing other than keep itself hosted online
I have tried finding an answer to this but everything is for Javascript
basically what I'm looking for is a bot that:
When someone sends a message detect if he has role "X"
If he has role "X" reply with a prewritten message
for example, if someone has a role named "PlaysROR2"
whenever he types the word game the bot will send the message ROR2
I'm new to making discord bots and python in general so the more specific the answer the better
from what I understood there's no Has_role function so it's pretty complicated
#client.event
async def on_message(message):
role = discord.utils.get(message.guild.roles, name="PlaysROR2")
if role in message.author.roles and message.content == "game":
await message.channel.send("ROR2")
else:
return
Try this? I'm not very good at discord.py, sorry, and I haven't tested this yet so it might not work.
have watchdog file observer. When specific file appears I obtain it and I want to send it into a discord channel.
What commands/events should I look at/use to do this? It's not coming from async discord function. Event is not coming from channel or message, but from obtaining of the file from the PC which bot is runnin on.
Thank you
I did not get the question well, though, if you want to do something when the bot comes online my suggestion is: use the on_ready event. Here is an example:
#client.event
async def on_ready():
await client.change_presence(activity=discord.Game('Hello!'))
print('Connected to bot: {}'.format(client.user.name))
print('Bot ID: {}'.format(client.user.id))
I'm currently programming a bot and my first goal is to make the bot welcome and say goodbye to members that join or leave, but the bot sends nothing, not even showing any error.
#client.event
async def on_member_join(member):
print(" System: A member has joined the server!")
def sprint(str):
for c in str + '\n':
sys.stdout.write(c)
sys.stdout.flush()
time.sleep(3./90)
sprint(" Bot: Oh hey, looks like "+member.name+" has joined..")
#send message to a specific channel
channel = client.get_channel(channel id from the welcome channel)
await channel.send("Hey! Welcome to the server, "+member.mention+"! I hope you read the #rules before doing anything, otherwise have fun and enjoy your stay!")
I did it last time before I recreated the script, but the on_member_join thing doesn't work, not even on_member_leave! (I'm doing the on_member_join first to check if it's working)
My alternate account rejoined my server, but the bot (except MEE6) didn't send anything.. Is there anything you guys can help me?
You'll need to enable the member intent by creating an instance of discord.Intents.default, setting Intents.members to True, and passing the instance into your commands.Bot or discord.Client constructor, like:
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(intents=intents)
You'll also need to enable the members intent in the Discord dev portal (https://discord.com/developers). Go to that url, click on your application, go to the Bot tab, scroll down to the 'privileged gateway intents' section, and enable the members intent.
Then, restart your bot, and member events should work.
(for more info, look at https://discordpy.readthedocs.io/en/latest/intents.html)
Not much to it really.
I just have a bot which has a chat filter function which i only want to run on my friends server. However i have the bot in multiple servers. What do i put before the code to make it only run in a certain server?
The most straightforward way would be to just put a conditional in your on_message definition that prevents it from taking action if the message wasn't from the given server.
async def on_message(message):
WHITELISTED_SERVER_ID = '01234567890123456789'
if message.channel.server.id == WHITELISTED_SERVER_ID:
// do whatever the bot does
You can adapt that to however your bot is designed. There are also other concerns (e.g. if the message is from a direct message, message.channel.server won't exist), but that's the gist of it.