I'm currently making a hug command.
Im trying to make my bot mention the the user that used to command and the one that the user mentioned while using the command, my main problem is the bot sends the '#user has hugged #user' outside of the embed,
here is the code that im using
const messages = ["https://media.tenor.com/images/c6f27ebfd8657a83794329468c27197f/tenor.gif"]
module.exports = {
name: 'embed',
description: "hug embed",
execute(message, args){
const randomMessage = messages[Math.floor(Math.random() * messages.length)]
const hugged = message.mentions.users.first();
const reply = message.reply(`has hugged! <#${hugged.id}>`);
if(!hugged) return message.reply('please mention who you want to hug');
let embeddedHug = new Discord.MessageEmbed()
.setDescription(reply)
.setImage(randomMessage)
message.channel.send(embeddedHug);
}
}
Any suggestions why the bot sends it ouside of the embed?
You are not doing it correctly.
message.reply() is used to send a normal message and automatically mention the author on the beginning of the message.
This is what you want.
const hugged = message.mentions.users.first();
const embedMessage = `<#!${message.author.id}> has hugged <#!${hugged.id}>`;
let embeddedHug = new Discord.MessageEmbed()
.setDescription(embedMessage)
.setImage(randomMessage)
message.channel.send(embeddedHug);
Related
I am working on a discord bot and want to make it able to ban and kick the users which I mention, the issue is that even if it does say that the user I mentioned was banned successfully, it really wasn't. How can I fix this?
kick.js
name: 'kick',
description: "`Executing this command will kick the given user.`",
execute(message, args){
const target = message.mentions.users.first();
if(target){
const memberTarget = message.guild.members.cache.get(target.id);
memberTarget.kick();
message.channel.send("**The given user has been kicked.**");
}else{
message.channel.send("`You have to specify who you want to kick!`");
}
}
}
ban.js
name: 'ban',
description: "`Executing this command will ban the given user.`",
execute(message, args){
const target = message.mentions.users.first();
if(target){
const memberTarget = message.guild.members.cache.get(target.id);
memberTarget.ban();
message.channel.send("**The given user has been banned.**");
}else{
message.channel.send("`You have to specify who you want to banned!`");
}
}
}
You can put the messages just before the kick/ban, so that the user is available for the client:
const memberTarget = message.guild.members.cache.get(target.id);
memberTarget.kick();
message.channel.send("**The given user has been kicked.**");
becomes
const memberTarget = message.guild.members.cache.get(target.id);
message.channel.send("** <#"+ target.id + "> has been kicked.**");
memberTarget.kick();
Hi guys i'm junior nodejs developper!
my question: How to clear chat on write text == cls
my code
const { chat, message_id } = message
const chatId = message.chat.id
const name = message.from.first_name
const text = message.text
// ================== on write "cls" clear chat
else if (text == 'cls') {
bot.deleteMessage(chatId, chat.id)
var msg = message;
}
I think currently there isn't any method to clear whole chat using bot but
you can use simple loop to delete last 100 messages(only work for group chats and bot should have admin permission to delete messages). Like this,
const Telegram = require('node-telegram-bot-api')
const TOKEN = process.env.TOKEN || "<YOUR BOT TOKEN>";
const bot = new Telegram(TOKEN,{polling:true})
bot.onText(/\/start/,(msg)=>{
bot.sendMessage(msg.chat.id,'Hello World!')
})
//I use bot command regex to prevent bot from miss understanding any user messages contain 'cls'
bot.onText(/\/cls/,(msg)=>{for (let i = 0; i < 101; i++) {
bot.deleteMessage(msg.chat.id,msg.message_id-i).catch(er=>{return})
//if there isn't any messages to delete bot simply return
}
}
)
Hopefully this might help you :D
Refer:
https://core.telegram.org/bots/api#deletemessage
Note: I'm a beginner, so if there are any mistakes, please excuse me.
Okay so, im trying to make an announce command that makes the bot say what the user asks it to write,
the command is working fine but the main problem is that i dont want users that are not moderators/admins to use this command i tried to use if (user.hasPermission("KICK_MEMBERS") but i simply don't know how to implement this into my code, (here it is)
const Discord = require('discord.js');
module.exports = {
name: 'announce',
description: "announce",
execute(message, args){
const developerEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle(`failed to send message`)
.setAuthor('♥Aiko♥', 'https://i.imgur.com/1q9zMpX.png')
.setDescription('please mention the channel first(if this promblem persists contact the developer)')
.setTimestamp()
.setFooter(`©Revenge#7005 | Requested by ${message.author.tag}.`);
if(message.mentions.channels.size === 0) {
message.channel.send(developerEmbed);
}
else {
let targetChannel = message.mentions.channels.first();
const args = message.content.split(" ").slice(2);
let userMessage = args.join(" ");
targetChannel.send(userMessage);
message.delete();
}
}
}
so yeah, any ideas how to make the bot check for the permission and then send the message if the user has it?
i'm pretty new to coding and this bot is my first bigger project so sorry if this question seems stupid
Make sure to use message.member in place of user, and you should implement it at the beginning of your code.
module.exports = {
name: 'announce',
description: "announce",
execute(message, args) {
if (!message.member.hasPermisson('KICK_MEMBERS')) // if member doesn't have permissions
return message.channel.send('Insufficient Permissions');
// rest of your code...
I am coding a discord bot using discord.js.
FOR SOME REASON it says Discord not defined error or the bot has no response. Please could you help me? I have never had this error before. Here's the code.
I have include this command in the same main.js file:
if(cmd === `${prefix}help`){
reporthelp = "Report a user. Requires a channel named `reports`to work!";
kickhelp = "Kick a user from the server. Requires a channel named `incidents` to work; you must have the manage messages permission.";
banhelp = "Ban a user from the server. Requires a channel named `incidents` to qork; toy need the BAN MEMBERS permission to use this command!";
warnhelp = "**COMMAND COMING SOON!**";
requiredperms = "**Embed Links, channel named `incidents`; channel named `reports`; channel named `suggestions`; Kick Members, Ban Members, Manage Roles, Manage Members.**"
helpEmbed = new Discord.RichEmbed()
.setDescription(" 💬 **__Help Is Here!__** 💬")
.setColor("#936285")
.addField("**/report #user <reason>**", reporthelp)
.addField("**(COMING SOON)** /warn #user <reason>", warnhelp)
.addField("**/kick #user <reason>**", kickhelp)
.addField("**/ban #user <reason>**", banhelp)
.addField("**/mytag**", "Shows you **your** discoord username#discrim and your user ID. Requires Embed Links permission.")
.addField("**/invite**", "Get a linkto incite meto our server, and an invite link to my suppoer server")
.addField("**/owner**", "see who currently owns the bot")
.addField("**/git**", "**SOURCE CODE AVAILIBLE SOON**")
.addField("**/token**", "View the bot's super secret bot token!")
.addField("**/serverinfo**", "displays some basic server information!")
.addField("**/botinfo**", "displays basic bot information!")
.addField("**/ping**", "Get the bot to respond with `pong` ")
.addField("**/hosting**", "Bot finds a good website for bot/web hosting")
.addField("**/quotes**", "bot responds with some lovely quotes!")
.addField("**__Required Permissions__**", requiredperms)
// .addField("**COMING SOON!**/suggest <suggestion>", "suggest something. Requires channel named `suggestions`")
.setTimestamp()
.setFooter("Use /invite to invite me to your server!")
return message.channel.send({embed: helpEmbed});
}
This is how I've defined everything:
const botconfig = require("./botconfig.json");
const tokenfile = require("./token.json");
const Discord = require("discord.js");
const bot = new Discord.Client({disableEveryone: true});
bot.on("ready", async () => {
console.log(`${bot.user.username} is active in ${bot.guilds.size} servers!`);
bot.user.setActivity("rewriteing main.js...", {type: "WATCHING"});
//bot.user.setGame("Lookin' out for ya!");
});
bot.on("message", async message => {
if(message.author.bot) return;
if(message.channel.type === "dm") return;
const prefix = botconfig.prefix;
const messageArray = message.content.split(" ");
const cmd = messageArray[0];
const args = messageArray.slice(1);
const bicon = bot.user.displayAvatarURL;
I either get no response/error, or I get the error discord is not defined.
I'm also very new here, sorry If I didn't ask a question clearly...
The code is correct, but I had redfined discord in a different part of the file....
my advice would be to alays read the code over again!
I'm trying to setup my bot to where whenever I run "=play" it will post an embed stating what is being played. But every time I try to run it the video loads fine, but the embed itself won't. Does anyone have any tips as to how to get it to work?
const Discord = require("discord.js");
const ytdl = require('ytdl-core');
exports.run = async (client, message, args, ops) => {
const embed = new Discord.RichEmbed()
.setAuthor('Please enter a voice channel','https://i.imgur.com/Tu6PraB.png')
.setDescription('You must be in a voice channel to play music!')
.setColor('#de2e43')
if (!message.member.voiceChannel) return message.channel.send({embed});
if (message.guild.me.voiceChannel) return message.channel.send('Sorry, the bot is already connected to the channel.');
if (!args[0]) return message.channel.send('Sorry, please input a url following the command.');
let validate = await ytdl.validateURL(args[0]);
if (!validate) return message.channel.send('Sorry, please input a **valid** url following the command.')
let info = await ytdl.getInfo(args[0]);
let connection = await message.member.voiceChannel.join();
let dispatcher = await connection.playStream(ytdl(args[0], { filter: 'audioonly'}));
var playing = new Discord.RichEmbed()
.setAuthor('Now playing')
.setDescription(`${info.title}`)
.setColor('#2ecc71')
message.channel.send({playing});
};
Once you finished making your embed, you forgot to add ; to the end of the statement in both embeds. Try fixing that problem and see if it works.
I found out the problem. message.channel.send({playing}); was incorrect. ({playing}) doesn't need to have the brackets around it, it just needs to sit inside the parenthesis.
So instead of message.channel.send({playing}); it would be message.channel.send(playing);.