How to send message using Bale bot into group?
for send message using BaleBot, we need to have id of User/Group and have an accessHash. But I can`t get accessHash for send mesage to Group.
It's not too hard, if you have id and access_hash of the group(or channel). you should just make the Peer and after that put it in send_message function.
look at this code. It push a "Hello" to a specified channel after getting start by client.
Note: Remember group and channel are similar.
const SDK = require("balebot");
const BaleBot = SDK.BaleBot;
const TextMessage = SDK.TextMessage;
const Group = SDK.Group;
let bot = new BaleBot('token');
bot.hears(["/start"], (message, responder) => {
console.log(responder._peer)
bot.send(new TextMessage("hello"),responder.peer).then((res) => {
console.log(res)
}).catch((err) => {
console.log(err)
});
});
Related
There is the way to edit a message on DiscordJS
To do this, we just need to pass it to the function, the client variable.
exports.myNewFunction = async function myNewTestFunction(client)
First, in order to edit a message using the Discord.JS API, we will need to find the server's GuildID.
const guild = client.guilds.cache.get(`Your Guild ID`);
Now, we're going to need to find the channel the message is on. For this, we will use the channel ID
const channel = guild.channels.cache.find(c => c.id === `Your message Channel` && c.type === 'text');
Finally, let's go to the editing part of the message. For this, we will only need to provide the ID of the message that you want to be edited.
channel.messages.fetch(`Your Message ID`).then(message => {
message.edit("New message Text");
}).catch(err => {
console.error(err);
});
I'm trying to make the bot receive DMS and send the received DMS into a channel. It already creates the channel and dms the user on command but idk how to receive & send the received dms in a channel. thanks for helping:)
run(client, message, args) {
message.guild.channels
.create(this.name, { type: 'text', })
.then((channel) => {
const catogaryID = '850020908596592713'
channel.setParent(catogaryID)
})
message.channel.send('<#839172815025340426> s1 needs help')
message.author.send('whats wrong')
What you can do is create a Map which stores the user's name and the channel that you want to post their messages to, something like this:
In your main file somewhere
// Stores the information somewhere that it can easily be retrieved
client.modmailThreads = new Map(); // I'm assuming this is what you want to achieve
Listening to new messages
client.on("message", message => {
// Your other code here
if(message.channel.type == "dm" && client.modmailThreads.get(message.author.id)) { // If this is a DM and the user has a modmail channel
client.channels.cache.get(client.modmailThreads.get(message.author.id)).send(message.content); // Get their modmail channel and send the message to it
}
});
In your current code
run(client, message, args) {
message.guild.channels
.create(this.name, { type: 'text', })
.then((channel) => {
const catogaryID = '850020908596592713'
channel.setParent(catogaryID)
client.modmailThreads.set(message.author.id, channel.id); // Store value
})
message.channel.send('<#839172815025340426> s1 needs help')
message.author.send('whats wrong')
Obviously this is only an example so you may want to do some more modifications yourself.
Having trouble sending a bot message on a specific channel. I very simply want to have the bot send a message to #general when it activates, to let everyone know it's working again.
In the bot.on function, I've tried the classic client.channels.get().send(), but the error messages I'm getting show that it thinks client is undefined. (It says "cannot read property 'channels' of undefined")
bot.on('ready', client => {
console.log("MACsim online")
client.channels.get('#general').send("#here");
})
The bot crashes immediately, saying: Cannot read property 'channels' of undefined
The ready event doesn't pass any client parameter.
To get a channel by name use collection.find():
client.channels.find(channel => channel.name == "channel name here");
To get a channel by ID you can simply do collection.get("ID") because the channels are mapped by their IDs.
client.channels.get("channel_id");
Here is an example I made for you:
const Discord = require("discord.js");
const Client = new Discord.Client();
Client.on("ready", () => {
let Channel = Client.channels.find(channel => channel.name == "my_channel");
Channel.send("The bot is ready!");
});
Client.login("TOKEN");
You need to get the guild / server by ID, and then the channel by ID, so your code will be something like :
const discordjs = require("discord.js");
const client = new discordjs.Client();
bot.on('ready', client => {
console.log("MACsim online")
client.guilds.get("1836402401348").channels.get('199993777289').send("#here");
})
Edit : added client call
The ready event does not pass a parameter. To gain the bot's client, simply use the variable that you assigned when you created the client.
From your code, it looks like the bot variable, where you did const bot = new Discord.Client();.
From there, using the bot (which is the bot's client), you can access the channels property!
I want to know the code that I can get the user that the bot isn't in his mutual servers and I have his id I want the bot to send him Direct Message what is the code?
I didn't try anything I'm a noob at this in learning
Use the Client.fetchUser() method.
Example 1:
let ID = '123456789012345678';
client.fetchUser(ID)
.then(user => user.send('hello'))
.catch(console.error);
Example 2 (must be within an async function):
let ID = '123456789012345678';
try {
let user = await client.fetchUser(ID);
await user.send('hello');
} catch(err) {
console.error(err);
}
im trying to get my super simple bot to send a message stating the user status. as if someone is offline, online,..etc it automatically sends a message to the server saying that happened.
im just doing a work around so it can get updated (i know i need to !status everytime)
anyone has an idea to make it send the same message instantly after presenceUpdate fires?
let userStatus = [];
bot.on("presenceUpdate", (oldMember, newMember) => {
let username = newMember.user.username;
let status = newMember.user.presence.status;
userStatus.push(username, status);
console.log(`${newMember.user.username} is now ${newMember.user.presence.status}`);
})
bot.on('message', (message) => {
// if (!message.content.startsWith(prefix)) return;
if (console.log())
let [username, status] = userStatus;
if (message.content.startsWith(prefix + "status")) {
let botembed = new Discord.RichEmbed()
.setDescription("Status Update")
.setColor("#FFF")
.addField('.............................................', `${username} is now ${status}`);
message.channel.send(botembed);
userStatus = [];
}
});
The issue I think you're running into is that you don't have a direct reference to a channel anymore, which is why you can't "easily" call <TextChannel>.send(...). You'll have to decide which channel you want to send a message to, in your presenceUpdate event listener. Once you decide, you can use this code to get a reference to that channel using the channel's name:
client.on('presenceUpdate', (oldMember, newMember) => {
// get a reference to all channels in the user's guild
let guildChannels = newMember.guild.channels;
// find the channel you want, based off the channel name
// -> replace '<YOUR CHANNEL NAME>' with the name of your channel
guildChannels.find('name', '<YOUR CHANNEL NAME>')
.send('test message!')
.then(msg => {
// do something else if you want
})
.catch(console.error)
});
Note: you don't have to use the channel's name property to identify a unique channel, you can use the channel's id by doing
guildChannels.get('<YOUR CHANNEL ID')
.send('...
Hope this helps!