I'm making a bot and need to let the user save the channelID to an array.
The rest of the code is fine and works as intended in a group, but it's totally unresponsive inside a channel.
I've if else statements for if the chat is a channel, group, supergroup or private to no avail.
I'm using the node-telegram-bot-api - here is the snippet:
bot.onText(/\/getid/, (msg) => {
console.log(`Channel/Group ID is: ${msg.chat.id}`);
});
bot.on('channel_post', (msg) => {
if (msg.text === "/getid") {
console.log(`Channel ID is: ${msg.chat.id}`);
}
});
I managed to solve with this.
Related
I'm new to programming and i'm trying to make a Discord bot for me and my friends, for now I have set up two commands, the first works fine, but the second one is the problem.
client.on('message', msg => {
if (msg.content === `#usertag#0001`) {
msg.channel.send(`<#${msg.author.id}> <#${msg.author.id}> <#${msg.author.id}> <#${msg.author.id}> don't tag me`);
}
});
So what it should do is when a specific user is tagged it sends a message, the message sent from the bot is working (it tags the user who sent the message 3 times and then it says something else), but the part where the bot recognizes the tag doesn't work.
I tried by putting the Discord id, using the full #, and other stuff, but it doesn't seem to work.
For this you could use the message.mentions method, and here is how you could use it for example:
// For Discord V13 'message' is deprecated and
// will be removed in the future, use 'messageCreate' instead.
client.on("message", msg => {
// Disable messages from bot to avoid endless loops / replies
if(msg.author.bot === true) return;
// Check if anyone is mentioned.
// Skip #everyone mentions to be checked.
if(msg.mentions.users.size > 0 && msg.mentions.everyone === false) {
if(msg.mentions.users.find(user => user.id === "ENTER USER ID HERE")) {
msg.channel.send(`<#${msg.author.id}> <#${msg.author.id}> <#${msg.author.id}> <#${msg.author.id}> don't tag me!`);
}
}
});
Hope this will help you! ! I have tested this with Discord V13, i'm not 100% sure if this will work on Discord V12 as well.
So my question is
Scenario:
Lets say there's a bot in my server that sends an embed message with the title "Hello", And adds a random reaction under it which acts like a trigger.
What I want to do:
I want my bot to detect the title of that embed message and if it matches to my if statement then it also clicks/adds the same reaction that the embed bot put under it.
If there's any confusion please let me know.
This code will only work on new messages and cached messages,
client.on("messageReactionAdd", (reaction, user) => {
const message = reaction.message;
const embeds = message.embeds;
//return if no embeds or if another user reacted instead of the bot itself
if(!embeds.length || user.id !== message.author.id) return;
const firstEmbed = embeds[0];
//add your logic here
if(firstEmbed.title !== "Hello") {
//react same
message.react(reaction.emoji);
}
});
For filtering out embeds you might need reference to
https://discord.js.org/#/docs/main/12.2.0/class/MessageEmbed
So I'm making this thing where you can do this command and it checks if you purchased a thing or not (it gets sent to staff). So I have that bit working but I'm stuck on how to do something like where the bot says, "Are you done with this?" and it reacts to that message with the ❎ and ✅. And when you press one of them, it does the code.
Or make it so it only reacts with the tick and detects when someone reacted to it.
Currently I have:
message.channel.send(new Discord.RichEmbed().setTitle("Rank-Up Application:").setDescription(`**If you wish to send an application to get Ranked-Up in the Discord & ROBLOX Group, this is the right place to do it! **`).setFooter("When you have done that, say done.").setColor("#ff4757")).then(() => {
message.channel.awaitMessages(filter, { maxMatches: 1, time: 90000, errors: ['time']})
.then(collected => {
message.channel.send(":grey_exclamation: **Sending...**")
client.channels.get(`622386044914106388`).send(new Discord.RichEmbed().setTitle("New Rank-Up!").addField(`**The user ${username} has sent in an application to get ranked. Please check the following links to see if you should rank him. Remember: True = Owns Class, False = Doesn't own Class.**`).addField(`Plus: ${plus}`).addField(`Advanced: ${advanced}`).setTimestamp().setFooter("When you have done that, say done.").setColor("#ff4757"))
So that last line of code is the bit it should say the message under. I'm quite stuck on this and don't even know what start code I should put.
Maybe something like this is what you're looking for. I use it on tickets for people to close them. Works fine for me.
message.channel.send(`Message that will have reactions on it.`).then(msg => {
msg.react('❌');
// Wait 300ms to make sure the tick emoji is made after the first reaction. Just incase the API is on the slow side.
setTimeout(function(){msg.react('✅');},300);
// Create a filter to collect, making sure it only checks for non bot users.
// If you want to check for the message author use user.id == message.author.id
const filterEmojis = (reaction, user) => {
return ['❌', '✅'].includes(reaction.emoji.name) && user.bot == false;
};
// Await for a user to react as per our filter above.
msg.awaitReactions(filterEmojis, {time: 60000}).then(collected => {
const reaction = collected.first();
// Check if the reaxtion is an X.
if(reaction.emoji.name === '❌') {
// Do something when this is reacted too.
}
// Check if the reaxtion is a tick.
if(reaction.emoji.name === '✅') {
// Do something when this is reacted too.
}
}).catch(() => {
// Catch errors.
});
}).catch(console.error);
Hi so I'm trying to make a discord bot that deletes certain words I've managed to do this but I want to make it so it will delete edited messages
This is what I've got so far
client.on('messageUpdate', message => {
if(config.FILTER_LIST.some(word => message.content.toLowerCase().includes(word))) {
message.delete()
}
})
But it won't delete the messages
See this cool doc page.
You can use client.on('messageUpdate'), which is triggered every time a message is edited.
client.on('messageUpdate', (oldMessage, newMessage) => {
newMessage.delete();
}
Disclaimer: this only works for cached messages, which means that your bot will only have access to the messages it was notified of when it was online. There is no way for the bot to have access to messages that were sent when it was offline.
My code is currently:
if (message.content == ",test") {
if (message.member.roles.find("name", "images")) {
message.channel.send( {
file: "http://www.drodd.com/images14/black11.jpg" // Or replace with FileOptions object
});
}
if (!message.member.roles.find("name", "images")) { // This checks to see if they DONT have it, the "!" inverts the true/false
message.reply('You need the \`images\` role to use this command.')
.then(msg => {
msg.delete(5000)
})
}
message.delete(100); //Supposed to delete message
return; // this returns the code, so the rest doesn't run.
}
If the user has the role 'images' I want the bot to send the image when they say ",test" and I want the user's ",test" message to be deleted after some seconds. However, this doesn't seem to be working.
I have tried to send the image without the role checking and that works.
How can I fix this?
This is because message.member.roles.find("name", "images") checks if the roles EXISTS in the guild. In order to find if someone has a role, you would use message.member.roles.has(myRole). To find the ID of a role dynamically, you would use this:
let myRole = message.guild.roles.find("name", "Moderators").id;.