I want to make a command using 2 files to do a fully customizable embed.
In the first file : When the user do the command 2 embeds appears, the first is empty and the second has options with emojis we can react See the base I already did
In the second file : I made that when the user react with the first emoji, the bot sends a message saying "please specifiate an embed title"
But now I don't now what to do to make the bot copy the user's message and paste it in the first embed as a title.
I tried things like
switch (emoji) {
case "🖋️":
message.channel.send('Spécifie un titre d\'embed !')
const filter = m => (message.author.id === m.author.id)
const userEntry = await message.channel.awaitMessages(filter, {
max: 1, time: 20000, errors: ['time']
});
if(!member.user.bot) {
if(userEntry) {
const newEmbedModifTitle = userEntry.content;
modifembed.setTitle(`${newEmbedModifTitle}`)
message.edit(modifembed);
}
}
break;
}
}
But or the bot copies the message "please specifiate an embed title" and paste it in the second embed, or it don't do anything.
I hope someone can help me !
I advise you to just do !send [Title] [Color] [Footer] [Show author] [Content] then split it in a args[] let.
Related
I am very new to Discord.js so please forgive me for any basic errors.
I am trying to create a command that will ask for a name, and then store the users input into a variable, however this is proving itself quite difficult.
After the program sends the message "What would you like to name your event?", I type "TEST", and then it sends another message saying "createevent", the command word.
client.on('message', async message => {
if (message.author.bot) return;
if (message.content.startsWith('createevent')) {
const filter = m => m.author.id === message.author.id;
message.channel.startTyping()
await sleep(500);
message.channel.stopTyping()
message.lineReply('What would you like to name your event?')
message.channel.awaitMessages(filter, {max: 1, time: 50000}).then(collected => {
const eventname = message.content;
message.channel.send(eventname);
})
}
});
First of all, you should stop the collector and, as you said you want to know the content that the user replies, the content in your case would be collected.content not message.content.
So I have been developing a bot recently and I have implemented the slash commands into said bot. I have come across the need for a type 5 command "response" but I can't seem to find good documentation on the slash commands. I can't seem to make it "stop thinking". Any help would be appreciated!
EDIT: I found that you need to edit the interaction response (https://discord.com/developers/docs/interactions/slash-commands#interaction-response) but I'm not using webhooks I'm using a bot and I don't want to have to get another npm library if I don't have to. So how do I edit my interaction?
I have solved this, if you want to know how I did here is some code.
if your interaction responder looks like this:
if (interaction.data.name === 'whatever') {
whatever.whatever (interaction)//i am using a command handler to put
//the actual event into a different file
}
and your "interaction message sender" looks like this: (notice it's type 5)
module.exports.whatever = (interaction) => {
client.api.interactions(interaction.id, interaction.token).callback.post({
data: {
type: 5
}
})
};
then it will say "{botname} is thinking" with a little ellipses, and after 15 minutes if nothing happens it will fail the interaction. If you want to make it "stop thinking" you have to edit the message. I am using the axios npm library (https://www.npmjs.com/package/axios) and if you just put in this code it should edit your interaction message. this goes at the top of your file with your requirements:
const axios = require('axios')
const appId = ''//bot id goes here
and somewhere near the bottom of your file maybe put in this:
const editInteraction = async (client, interaction, response) => {
const data = typeof response === 'object' ? { embeds: [ response ] } : { content: response };
const channel = await client.channels.resolve(interaction.channel_id);
return axios
.patch(`https://discord.com/api/v8/webhooks/${appId}/${interaction.token}/messages/#original`, data)
.then((answer) => {
return channel.messages.fetch(answer.data.id)
})
};
then you will have the basic code structure to edit the message, now you just need to edit the message. to do that, in your code, do this:
if (interaction.data.name === 'whatever') {
whatever.whatever (interaction).then(m => {
editInteraction(client, interaction, '>:(')//this will actually edit the message so
//instead of " >:( " put in what you want to edit you message to be
})
}
then you can run that command and it will say the bot is thinking then after whatever event you want to run it will edit it to say whatever!
This is my first time using js. I need to ban a certain word in a certain channel. I don't want the message to be deleted if it is not in the specific channel.
For Example:
I want to ban the word "goodbye" in the #greeting channel
BUT
I don't want to ban the word "goodbye" In the #farewell channel
How would I go about this?
Thanks.
By the way I wanted to use example code, but none of it made any sense.
I wrote a simple example for you on how to achieve this:
const Discord = require("discord.js");
const Client = new Discord.Client();
const ForbiddenWords = {
"ChannelID": ["goodbaye", "bye"] // Greeting channel
};
Client.on("ready", () => {
console.log(`${Client.user.tag} is ready!`);
});
Client.on("message", (message) => { // Fired when the bot detects a new message.
if (message.author.bot) {return false}; // Checking if the message author is a bot.
if (ForbiddenWords[message.channel.id]) { // Checking if the current channel has any forbidden words in the ForbiddenWords Object
if (ForbiddenWords[message.channel.id].some(word => message.content.toString().toLowerCase().includes(word))) { // Checking if the message contains any forbidden words
message.delete(); // Deleting the message.
};
};
});
Client.login(process.env.DISCORD_AUTH_TOKEN);
Okay. This might be a strange question, but I need help as I could not find anything online. I have a discord bot and server that is hosts a competition, and users submit their submissions by Direct Messaging me a link or file of their submission. I would like to change this to them DMing the bot instead, and the bot posting the links and files in a certain channel in the server. I have absolutely no clue how to achieve this as I am kind of a novice when it comes to this sort of thing. Please comment if I need to change my wording or need to clarify anything!
Replace channel id with the actual id of the channel that you want to send the submissions to.
For Discord.js v12/v13 (the latest version):
client.on('message', ({attachments, author, content, guild}) => {
// only do this for DMs
if (!guild) {
// this will simply send all the attachments, if there are any, or the message content
// you might also want to check that the content is a link as well
const submission = attachments.size
? {files: [...attachments.values()], content: `${author}`}
: {content: `${content}\n${author}`}
client.channels.cache.get('channel id').send(submission)
}
})
For Discord.js v11 replace
client.channels.cache.get('channel id').send(submission)
with
client.channels.get('channel id').send(submission)
In the message event, you can check if the message is in a dm channel then you can take the message content and send it to a specific channel as an embed.
Your solution would be:
client.on('message', (message) => {
if (message.channel.type === 'dm') {
const channel = client.guilds.cache.get("GUILD_ID").channels.cache.get("CHANNEL_ID");
const embed = new Discord.MessageEmbed()
.setAuthor(message.author.tag, message.author.avatarURL())
.setColor('RANDOM')
.setDescription(message.content)
channel.send(embed);
if (message.attachments.array().length) {
message.attachments.forEach((attachment) => channel.send({ files: [ attachment ] }))
}
}
})
I am trying to make a Discord bot for announcements. I want to create a command which will read the data from the message and convert it into Embedded message.
An example command: !announce Title, Description, Link, Image
const Discord = require('discord.js');
const bot = new Discord.Client();
//listener
bot.on('ready', () => {
bot.user.setGame('Hello!')
});
bot.on('message', (message) => {
if(message.content == 'text') {
const embed = new Discord.RichEmbed()
.setTitle("Title!")
.setDescription("Description")
.setImage("https://i.imgur.com/xxxxxxxx.png")
.setURL("https://google.com")
.addField("Text", true)
//Nope
.setThumbnail("https://i.imgur.com/Rmiwd1j.png")
.setColor(0x00AE86)
.setFooter("Footer", "https://i.imgur.com/xxxxxxxx.png")
.setTimestamp()
/*
* Blank field, useful to create some space.
*/
message.channel.send({embed});
}});
bot.login('token');
I want Embed to be changed based on the text.
How can I do this?
First, you'll need to detect the command: you can use String.startsWith() to detect !announce:
if (message.content.startsWith('!announce')) {...}
Then you'll have to get the other parts of the command by splitting the string: you can separate them with a comma, as you did (title, description, ...), or with whatever character you want (I'll use a comma in my example).
String.slice() will help you get rid of the !announce part, while String.split() will create an Array with the other parts.
This code will generate an embed like this from the command !announce Title, Description, http://example.com/, http://www.hardwarewhore.com/wp-content/uploads/2018/03/dcord.png
client.on("message", message => {
if (message.content.startsWith('!announce')) {
let rest_of_the_string = message.content.slice('!announce'.length); //removes the first part
let array_of_arguments = rest_of_the_string.split(','); //[title, description, link, image]
let embed = new Discord.RichEmbed()
.setTitle(array_of_arguments[0])
.setDescription(array_of_arguments[1])
.setImage(array_of_arguments[3])
.setURL(array_of_arguments[2])
.addField("Text", true)
.setThumbnail("https://i.imgur.com/Rmiwd1j.png")
.setColor(0x00AE86)
.setFooter("Footer", array_of_arguments[3])
.setTimestamp();
message.channel.send({ embed });
}
});
I suggest using the text instead of the description and remind that the second argument of the .addField() is the text, not the inline value