I want to send a message in a Discord channel but from a user account not a bot. Is this kind of thing possible using Discord's API?
The official documentation should contain enough information to get started: https://discord.com/developers/docs/resources/channel#create-message
Make sure to login with OAuth2 and not as a bot. Also, it is important to get the right scope (permissions) when requesting an OAuth token.
I'd like to abide by TOS but i am having tough time. I'm in paid server where I can't place a bot account. I simply want to consume the message content in my application (currently in python). What can I do? Can I write a hook to consume the messages from the GUI or from the web client? It seems what I want to do is not supported. Any thoughts?
Others have stated that you can apparently use use ipc and messages.read scope or RPC to receive messages but I don't know what resources are available to hook into and get the message content as it comes from the server.
There are multiple ways to read the messages from the client. You could use the Discord API with your account's token, but this is not allowed by the Discord ToS and thus is bannable (self botting). The other way is to use Discord IPC.
Discord IPC allows you to communicate with the Discord client by using named pipes. The default name is discord-ipc-0. You need a Discord application to use it.
The IPC protocol uses the same protocol as RPC, which is documented on Discord Developer Portal. You can also find more information on the IPC protocol on the discord-rpc official repo.
To put it simply, the packets you send through the pipe are serialized that way:
uint32 opcode
uint32 length
byte[length] jsonData
The data is a JSON encoded object, with a unique nonce parameter that is sent back on the answer, a cmd parameter for the command you want to use and optionally args and evt.
You would probably be interested in the AUTHORIZE, AUTHENTICATE, GET_CHANNEL and SUBSCRIBE commands. So I'll explain those four commands here.
But first, you need to connect to the IPC and do the handshake. This is done by sending a message with the opcode 0, your client_id and the protocol version. Here's what the JSON object should look like:
{
"v": 1,
"client_id": 332269999912132097
}
Once you're connected, you should receive a DISPATCH response with the user info. Every message you will send from this point should use the opcode 1
Now, you need to send an AUTHORIZE command This command allows you to ask an OAuth2 code from the client with the specified scopes, which will allow you to use the AUTHENTICATE command. Here, you would want the rpc and messages.read scopes. It should look like this:
{
"nonce": "be9a6de3-31d0-4767-a8e9-4818c5690015",
"cmd": "AUTHORIZE",
"args": {
"client_id": 332269999912132097,
"scopes": "rpc messages.read"
}
}
Please note that you need a redirect uri on your application for this to work.
The client should get a prompt. If he accepts, then your application would receive an oauth2 code that you can use to authenticate. The OAuth2 process is explained on the Discord Developer Portal.
After making your request to /oauth2/token with the code, your client id, client secret and redirect uri, you should be getting an access token that you can to authenticate, using the AUTHENTICATE command. Here is what it should look like:
{
"nonce": "5dc0c062-98c6-47a0-8922-bbb52e9d6afa",
"cmd": "AUTHENTICATE",
"args": {
"access_token": "CZhtkLDpNYXgPH9Ml6shqh2OwykChw"
}
}
If the authentication is successful, you should receive a response with evt set to null, application info and user info.
From this point, you are authenticated and you can read messages by using the GET_CHANNEL command to get the last messages, and by subscribing to the MESSAGE_CREATE event to get the new messages when they're sent. Those are documented on the Developer Portal.
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')
I want to send message to a user any time using facebook messenger API.
I'm using developer version of messaging app and has not submitted for review yet.
We are two friends both as developer in the app. I want when my friend sends message to my page, Bot replies and a copy of message sent by friend comes to my inbox. But when I tried api throws following error.
{"error":{"message":"(#100) Parameter error: You cannot send messages to this id","type":"OAuthException","code":100,"fbtrace_id":"HRTLdvidA4u"}}
Is there any solution.
Thanks.
Is it possible to receive direct messages on behalf of a slack bot via POST requests to a certain domain?
I want to have an endpoint in Google App Engine that receives incoming direct messages from Slack via POST requests, and posts messages back via the API. Is it possible?
You can use the new Events API. Create a bot, subscribe to message.im events, and set your endpoint as the callback URL
You just need to set up an "outgoing webhook"in slack and point it to whatever endpoint you need on your GAE server. In order to respond just use an "incoming webhook" to receive the answer.