I'm a beginner-intermediate level programmer working with discord.py for the first time. I want to create two bots that, when one is prompted, both send messages one after another as if in a conversation.
Is that even possible in discord.py? I considered making two different bots in two different .py files, creating variables for each line of the conversation for both bots, and then having them each prompt if the message content matched the variable. However, I don't want the bots to prompt if the line is said by someone other than the other bot.
Any advice? Thanks so much!
You can use on_message event and check if the id of the author is the id of second bot. Example:
#bot.event
async def on_message(message):
if not message.author.id == 0000: # id of another bot
return
# rest of the code
You can use the discord-ext-ipc lib.
You can setup a server on both bots and exchange Http Messages whenever an specific Event triggered on one bot.
Related
I've seen some bot creators before with options to extract all members of bot who interacted (or started) bot before. but I can't find any method in telegram docs for extract users. Do you know any method for extract users of bot in any library or something?
I asked ChatGPT but he gives me a code for extract chat users:
async def get_users(client, message):
if message.text == "/users":
# get all users who have ever interacted with the bot
async for member in app.iter_chat_members(chat_id=message.chat.id):
user = member.user
if user.is_bot:
continue
if user.status == 'restricted' or user.status == 'kicked':
continue
How can I get UserID from user who started my bot before if I didn't save it?
there is any method for extract users of bot in any library or something?
How can I get UserID from user who started my bot before if I didn't save it?
You cant!
After you've passed an offset to the getUpdates call to remove any messages from the update queue, they're gone. Reff
There is no way to ask Telegram for a list of chat's that ever talked with your bot.
The only way of doing this is by a custom implementation where you save each chat id somewhere to recall later.
I wanted that when I marked a user, the bot added him to the server, I already did something similar, but he only sent an invitation.
ps: I don't have a code example here to add the question, but my bot is in python
#bot.command
async def add_member(ctx, member: discord.Membrer):
await guild.add_member(member)
what I just typed is a theoretical code, I don't know if these commands exist, it's just to illustrate the idea I had
This isn't possible using the bot API. You'll need to make your target user go through the OAuth2 flow with the scope guilds.join, after which you can use the /guilds/{guild.id}/members/{user.id} endpoint with the token you will get to join a guild on a specific user's behalf.
I'm trying to make a discord bot say a certain message when it first joins a Discord Server, so when the bot first joins a Discord Server, it will say something along the lines of "Hello everyone....". I looked at a lot of sources but none seem to be,Can anyone help?
make a bot say a certain message when it first joins a server
Heyo.
To make your bot say something in a channel, you just use a client event.
Code example:
#client.event
async def on_guild_join(guild):
await channel.send("Wassup!")
Please keep in mind that you need to define the channel variable.
Remember that this requires Intents.guilds to be enabled!
You can check all of this on the discord.py docs. https://discordpy.readthedocs.io/en/stable/api.html?highlight=event#discord.on_guild_join
I haven't been looking for an answer to this question for a long time, but I closed it and the help on the browser history didn't help in any way. I tried to do it myself, but it didn't work out. I wanted to make it so that if the bot did not have rights, then he wrote about it and if there were, then he did the action, please help!
Note: This message is written assuming you are using the standard discord.py events and not the bot events, but it obviously also works with the bot events. Just replace "client" with "bot" and instead of "message" use "ctx.message".
You can get your client user via
client.user
To get the member object of the client user, you can use
message.channel.guild.get_member(client.user.id)
Documentation
On member objects you can then call guild_permissions
member.guild_permissions
Documentation
Permission objects are documented here.
Here is an example that sends a message if the bot cannot react to messages.
#client.event
async def on_message(message):
client_member = message.channel.guild.get_member(client.user.id)
if not client_member.guild_permissions.add_reactions:
await message.channel.send("I cannot add reactions in this channel")
return
I have a problem with mentioning role with discord webhook. I'm using discord_webhook library.
When I try to mention a role webhook tags it and it looks fine but it didn't really ping users from that group. The message isn't also highlighted for them. That's not how the group mention should work
In code my mention looks like this:
<#&823xxxxxxxxxxx01>
But in real webhook:
webhook
Do you know how to make the webhook with notification highlithed for specific group? Of course my ping doesn't make classic discord ping sound (or notification)
You can not ping someone inside embed message. You need to send ping first, embed then (or embed first and ping seccond).
It's because discord is thinking you are doing some kind of role list without mentions (like role shop)