I'm wondering how this is possible? Discord bot - discord

I recently receive a 2 message in discord with invite link to server I received it from bot who doesn't share the same server with me or anything
How this is possible, I find some py codes but only work if the user and bot share same server
from discord.ext.commands import Bot, Greedy
from discord import User
bot = Bot(command_prefix='!')
#bot.command()
async def pm(ctx, users: Greedy[User], *, message):
for user in users:
await user.send(message)
bot.run("TOKEN")
How can I make one send messages to list of IDs not in same server?

Maybe the bot left the server after he sent the invite to everyone.
You could check if one of the bots was in the servers in the audit-log.

you could either get the user by id with the guild.get_member(id). That requires the user to be on that specific guild you try to get the user.
Or you can use bot.get_user(id) / await bot.fetch_user(id). There the bot tries to get the user. If found you can do sth with it else it will return None or raises the command Error UserNotFound.
A bot that has no mutal guild with a specific user cannot send a dm to them.
Also what purpuse is it to send dms to multiple users from a list?
Keep in mind that its against the Discord TOS to mass dm users without permissions. If they did not opt in sth to get dms I would not send random dms do multiple users.

Related

Discord. How can I send a message to my bot from another app?

How do I send a specific message to my bot (not a channel) from my website (using a webhook or otherwise)? This is necessary to provide the bot with instructions (commands). The data will be sent in json format with a specific structure.
In the server settings -> Integrations -> My bot, I see the "Webhooks" section, but I don't understand how to add hooks to my bot

discord - send message to bot from client

I am using discord.js
The scenario is something like this:
User posts something in one of the channel.
Bot replies to this user in a DM with
msg.author.send("I am the bot, and sending you this message as DM")
now, I want user to reply back to this bot in the DM again and i want bot and this user to communicate in the DM.
It seems like I can't achieve the user to send back the message to bot in the same DM.
I am using discord.js
Any idea ?
to dm a person, you must use message.author.send("Your message here.")
but you must have client code.

Is it possible to find out what discord bot a token belongs to?

I got multiple discord bots and sometimes it would be useful to find out to what bot a token belongs to via the API or some other way?
I'm using Javachord and I've found there's a getYourself() in DiscordApi that returns a User which represents the current bot.
I'm not sure how that maps to the Discord API itself though
Here's an alternative solution.
Discord has an API endpoint users/#me that returns the current user's user object.
Try this for an example:
curl -H "Authorization: Bot <token>" https://discord.com/api/v9/users/#me
Discord also sends back a user object (part of lots more info) as part of the Identify process when using its websocket gateways, but this probably isn't what you would want.

How to send message to a specific user from discord bot using discord.js

I want to send a message from my discord bot to a specific user like myself using my discord id.
I have tried the following code where my client object is named as bot:
bot.users.get("My Id copied from discord").send("Message to Send");
but it gives the following error in the terminal:
bot.users.get is not a function
Please help me in resolving this error.
Thank you
Since discord.js v12 you need to use cache to access the users collection
bot.users.cache.get('ID').send('hello')
You need to use users.fetch() instead since the user might not be cached
const user = await bot.users.fetch('ID')
user.send('hello')

Is it possible to DM a user from their username from a Discod.js bot

I need a Discord.js bot to DM a user if an API gives it a username. Is it possible to DM a user via a bot?
From the docs: you can search Client.users via Collection.find() by comparing a user's User.tag:
let user = client.users.find(u => u.tag === "someUser#1234");
Then you can send them a DM via User.send():
user.send("A message from a bot");
Note that the bot and said user must at least share a server for the bot to be able to access this user.

Resources