How to get discord bot to read embed
up vote
0
down vote
favorite
I understand how a discord bot can read a regular user inputed message and respond using
if(message.content.toLowerCase().includes('cyber'))
message.channel.send("Key Word Detected ");
But it won't read the message if it is an embed. Please help me change that to look for the keyword in a embed message and elicit a response from the bot.
javascript discord discord.js
add a comment |
up vote
0
down vote
favorite
I understand how a discord bot can read a regular user inputed message and respond using
if(message.content.toLowerCase().includes('cyber'))
message.channel.send("Key Word Detected ");
But it won't read the message if it is an embed. Please help me change that to look for the keyword in a embed message and elicit a response from the bot.
javascript discord discord.js
It sounds like you're asking for SO to write code for you. Could you show what you've tried to change within those lines, and explain why it didn't work? Maybe link the part of the docs you're trying to deal with
– TankorSmash
Nov 8 at 5:30
I tried changing the code to look likeif(embed.Message.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected ");
if(embed.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected ");
nothing seems to be working and everything I've looked up seems to not have any solution to my problem
– Mark Farag
Nov 8 at 5:44
Are you sure that embed.Message exists ? For me, after looking at this guide, it seems like an embed is a list of fields, so I would do something likefields = message.embed.fields; len = fields.length; for var i in range(len){ if fields[i].value.contains('cyber')...
– Djazouli
Nov 8 at 6:25
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I understand how a discord bot can read a regular user inputed message and respond using
if(message.content.toLowerCase().includes('cyber'))
message.channel.send("Key Word Detected ");
But it won't read the message if it is an embed. Please help me change that to look for the keyword in a embed message and elicit a response from the bot.
javascript discord discord.js
I understand how a discord bot can read a regular user inputed message and respond using
if(message.content.toLowerCase().includes('cyber'))
message.channel.send("Key Word Detected ");
But it won't read the message if it is an embed. Please help me change that to look for the keyword in a embed message and elicit a response from the bot.
javascript discord discord.js
javascript discord discord.js
asked Nov 8 at 4:11
Mark Farag
1
1
It sounds like you're asking for SO to write code for you. Could you show what you've tried to change within those lines, and explain why it didn't work? Maybe link the part of the docs you're trying to deal with
– TankorSmash
Nov 8 at 5:30
I tried changing the code to look likeif(embed.Message.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected ");
if(embed.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected ");
nothing seems to be working and everything I've looked up seems to not have any solution to my problem
– Mark Farag
Nov 8 at 5:44
Are you sure that embed.Message exists ? For me, after looking at this guide, it seems like an embed is a list of fields, so I would do something likefields = message.embed.fields; len = fields.length; for var i in range(len){ if fields[i].value.contains('cyber')...
– Djazouli
Nov 8 at 6:25
add a comment |
It sounds like you're asking for SO to write code for you. Could you show what you've tried to change within those lines, and explain why it didn't work? Maybe link the part of the docs you're trying to deal with
– TankorSmash
Nov 8 at 5:30
I tried changing the code to look likeif(embed.Message.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected ");
if(embed.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected ");
nothing seems to be working and everything I've looked up seems to not have any solution to my problem
– Mark Farag
Nov 8 at 5:44
Are you sure that embed.Message exists ? For me, after looking at this guide, it seems like an embed is a list of fields, so I would do something likefields = message.embed.fields; len = fields.length; for var i in range(len){ if fields[i].value.contains('cyber')...
– Djazouli
Nov 8 at 6:25
It sounds like you're asking for SO to write code for you. Could you show what you've tried to change within those lines, and explain why it didn't work? Maybe link the part of the docs you're trying to deal with
– TankorSmash
Nov 8 at 5:30
It sounds like you're asking for SO to write code for you. Could you show what you've tried to change within those lines, and explain why it didn't work? Maybe link the part of the docs you're trying to deal with
– TankorSmash
Nov 8 at 5:30
I tried changing the code to look like
if(embed.Message.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected ");
if(embed.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected ");
nothing seems to be working and everything I've looked up seems to not have any solution to my problem– Mark Farag
Nov 8 at 5:44
I tried changing the code to look like
if(embed.Message.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected ");
if(embed.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected ");
nothing seems to be working and everything I've looked up seems to not have any solution to my problem– Mark Farag
Nov 8 at 5:44
Are you sure that embed.Message exists ? For me, after looking at this guide, it seems like an embed is a list of fields, so I would do something like
fields = message.embed.fields; len = fields.length; for var i in range(len){ if fields[i].value.contains('cyber')...
– Djazouli
Nov 8 at 6:25
Are you sure that embed.Message exists ? For me, after looking at this guide, it seems like an embed is a list of fields, so I would do something like
fields = message.embed.fields; len = fields.length; for var i in range(len){ if fields[i].value.contains('cyber')...
– Djazouli
Nov 8 at 6:25
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
This should be it, checking for all embeds in the message too
if(message.content.toLowerCase().includes('cyber'))
message.channel.send("Key Word Detected ");
else {
for(var i = 0; i < message.embeds.length; i++) {
if(message.embeds[i].title.includes("cyber") || message.embeds[i].title.includes("cyber")) {
message.channel.send("Detected");
break;
}
}
add a comment |
up vote
0
down vote
The text in a MessageEmbed
can be in author
, description
, footer
, message.content
and title
. They can also be inside every filed, so might want to check for all that stuff.
Here's a little function you could use (I know it seems a mess but it's just because there are a lot of logical operators):
/*
message {Discord.Message}: the message you want to search in
target {string}: the string you're looking for
{
caseSensitive {boolean}: whether you want the search to be case case-sensitive
author {boolean}: whether you want to search in the author's name
description {boolean}: whether you want to search in the description
footer {boolean}: whether you want to search in the footer
title {boolean}: whether you want to search in the title
fields {boolean}: whether you want to search in the fields
}
*/
function findInMessage(message, target, {
caseSensitive = false,
author = false,
description = true,
footer = true,
title = true,
fields = true
}) {
if (!target || !message) return null;
let str = caseSensitive ? target : target.toLowerCase();
if ((caseSensitive && message.content.includes(str)) ||
(!caseSensitive && message.content.toLowerCase().includes(str))) return true;
for (let embed of message.embeds) {
if ((caseSensitive && (
(author && embed.author.includes(str)) ||
(description && embed.description.includes(str)) ||
(footer && embed.footer.includes(str)) ||
(title && embed.title.includes(str)))) ||
(!caseSensitive && (
(author && embed.author.toLowerCase().includes(str)) ||
(description && embed.description.toLowerCase().includes(str)) ||
(footer && embed.footer.toLowerCase().includes(str)) ||
(title && embed.title.toLowerCase().includes(str))))
) return true;
if (fields)
for (let field of embed.fields) {
if ((caseSensitive && [field.name, field.value].includes(str)) ||
(!caseSensitive && [field.name.toLowerCase(), field.value.toLowerCase()].includes(str))) return true;
}
}
return false;
}
The functions returns true
when finds the word you put in, false
when it doesn't find it and null
when one of the non-optional arguments is missing.
You can use it like this:
if (findInMessage(message, 'cyber')) message.channel.send("Key word detected.");
There are some instructions at the top, hope this helps ;)
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
This should be it, checking for all embeds in the message too
if(message.content.toLowerCase().includes('cyber'))
message.channel.send("Key Word Detected ");
else {
for(var i = 0; i < message.embeds.length; i++) {
if(message.embeds[i].title.includes("cyber") || message.embeds[i].title.includes("cyber")) {
message.channel.send("Detected");
break;
}
}
add a comment |
up vote
0
down vote
This should be it, checking for all embeds in the message too
if(message.content.toLowerCase().includes('cyber'))
message.channel.send("Key Word Detected ");
else {
for(var i = 0; i < message.embeds.length; i++) {
if(message.embeds[i].title.includes("cyber") || message.embeds[i].title.includes("cyber")) {
message.channel.send("Detected");
break;
}
}
add a comment |
up vote
0
down vote
up vote
0
down vote
This should be it, checking for all embeds in the message too
if(message.content.toLowerCase().includes('cyber'))
message.channel.send("Key Word Detected ");
else {
for(var i = 0; i < message.embeds.length; i++) {
if(message.embeds[i].title.includes("cyber") || message.embeds[i].title.includes("cyber")) {
message.channel.send("Detected");
break;
}
}
This should be it, checking for all embeds in the message too
if(message.content.toLowerCase().includes('cyber'))
message.channel.send("Key Word Detected ");
else {
for(var i = 0; i < message.embeds.length; i++) {
if(message.embeds[i].title.includes("cyber") || message.embeds[i].title.includes("cyber")) {
message.channel.send("Detected");
break;
}
}
edited Nov 8 at 11:36
answered Nov 8 at 11:00
Tom Martin
816
816
add a comment |
add a comment |
up vote
0
down vote
The text in a MessageEmbed
can be in author
, description
, footer
, message.content
and title
. They can also be inside every filed, so might want to check for all that stuff.
Here's a little function you could use (I know it seems a mess but it's just because there are a lot of logical operators):
/*
message {Discord.Message}: the message you want to search in
target {string}: the string you're looking for
{
caseSensitive {boolean}: whether you want the search to be case case-sensitive
author {boolean}: whether you want to search in the author's name
description {boolean}: whether you want to search in the description
footer {boolean}: whether you want to search in the footer
title {boolean}: whether you want to search in the title
fields {boolean}: whether you want to search in the fields
}
*/
function findInMessage(message, target, {
caseSensitive = false,
author = false,
description = true,
footer = true,
title = true,
fields = true
}) {
if (!target || !message) return null;
let str = caseSensitive ? target : target.toLowerCase();
if ((caseSensitive && message.content.includes(str)) ||
(!caseSensitive && message.content.toLowerCase().includes(str))) return true;
for (let embed of message.embeds) {
if ((caseSensitive && (
(author && embed.author.includes(str)) ||
(description && embed.description.includes(str)) ||
(footer && embed.footer.includes(str)) ||
(title && embed.title.includes(str)))) ||
(!caseSensitive && (
(author && embed.author.toLowerCase().includes(str)) ||
(description && embed.description.toLowerCase().includes(str)) ||
(footer && embed.footer.toLowerCase().includes(str)) ||
(title && embed.title.toLowerCase().includes(str))))
) return true;
if (fields)
for (let field of embed.fields) {
if ((caseSensitive && [field.name, field.value].includes(str)) ||
(!caseSensitive && [field.name.toLowerCase(), field.value.toLowerCase()].includes(str))) return true;
}
}
return false;
}
The functions returns true
when finds the word you put in, false
when it doesn't find it and null
when one of the non-optional arguments is missing.
You can use it like this:
if (findInMessage(message, 'cyber')) message.channel.send("Key word detected.");
There are some instructions at the top, hope this helps ;)
add a comment |
up vote
0
down vote
The text in a MessageEmbed
can be in author
, description
, footer
, message.content
and title
. They can also be inside every filed, so might want to check for all that stuff.
Here's a little function you could use (I know it seems a mess but it's just because there are a lot of logical operators):
/*
message {Discord.Message}: the message you want to search in
target {string}: the string you're looking for
{
caseSensitive {boolean}: whether you want the search to be case case-sensitive
author {boolean}: whether you want to search in the author's name
description {boolean}: whether you want to search in the description
footer {boolean}: whether you want to search in the footer
title {boolean}: whether you want to search in the title
fields {boolean}: whether you want to search in the fields
}
*/
function findInMessage(message, target, {
caseSensitive = false,
author = false,
description = true,
footer = true,
title = true,
fields = true
}) {
if (!target || !message) return null;
let str = caseSensitive ? target : target.toLowerCase();
if ((caseSensitive && message.content.includes(str)) ||
(!caseSensitive && message.content.toLowerCase().includes(str))) return true;
for (let embed of message.embeds) {
if ((caseSensitive && (
(author && embed.author.includes(str)) ||
(description && embed.description.includes(str)) ||
(footer && embed.footer.includes(str)) ||
(title && embed.title.includes(str)))) ||
(!caseSensitive && (
(author && embed.author.toLowerCase().includes(str)) ||
(description && embed.description.toLowerCase().includes(str)) ||
(footer && embed.footer.toLowerCase().includes(str)) ||
(title && embed.title.toLowerCase().includes(str))))
) return true;
if (fields)
for (let field of embed.fields) {
if ((caseSensitive && [field.name, field.value].includes(str)) ||
(!caseSensitive && [field.name.toLowerCase(), field.value.toLowerCase()].includes(str))) return true;
}
}
return false;
}
The functions returns true
when finds the word you put in, false
when it doesn't find it and null
when one of the non-optional arguments is missing.
You can use it like this:
if (findInMessage(message, 'cyber')) message.channel.send("Key word detected.");
There are some instructions at the top, hope this helps ;)
add a comment |
up vote
0
down vote
up vote
0
down vote
The text in a MessageEmbed
can be in author
, description
, footer
, message.content
and title
. They can also be inside every filed, so might want to check for all that stuff.
Here's a little function you could use (I know it seems a mess but it's just because there are a lot of logical operators):
/*
message {Discord.Message}: the message you want to search in
target {string}: the string you're looking for
{
caseSensitive {boolean}: whether you want the search to be case case-sensitive
author {boolean}: whether you want to search in the author's name
description {boolean}: whether you want to search in the description
footer {boolean}: whether you want to search in the footer
title {boolean}: whether you want to search in the title
fields {boolean}: whether you want to search in the fields
}
*/
function findInMessage(message, target, {
caseSensitive = false,
author = false,
description = true,
footer = true,
title = true,
fields = true
}) {
if (!target || !message) return null;
let str = caseSensitive ? target : target.toLowerCase();
if ((caseSensitive && message.content.includes(str)) ||
(!caseSensitive && message.content.toLowerCase().includes(str))) return true;
for (let embed of message.embeds) {
if ((caseSensitive && (
(author && embed.author.includes(str)) ||
(description && embed.description.includes(str)) ||
(footer && embed.footer.includes(str)) ||
(title && embed.title.includes(str)))) ||
(!caseSensitive && (
(author && embed.author.toLowerCase().includes(str)) ||
(description && embed.description.toLowerCase().includes(str)) ||
(footer && embed.footer.toLowerCase().includes(str)) ||
(title && embed.title.toLowerCase().includes(str))))
) return true;
if (fields)
for (let field of embed.fields) {
if ((caseSensitive && [field.name, field.value].includes(str)) ||
(!caseSensitive && [field.name.toLowerCase(), field.value.toLowerCase()].includes(str))) return true;
}
}
return false;
}
The functions returns true
when finds the word you put in, false
when it doesn't find it and null
when one of the non-optional arguments is missing.
You can use it like this:
if (findInMessage(message, 'cyber')) message.channel.send("Key word detected.");
There are some instructions at the top, hope this helps ;)
The text in a MessageEmbed
can be in author
, description
, footer
, message.content
and title
. They can also be inside every filed, so might want to check for all that stuff.
Here's a little function you could use (I know it seems a mess but it's just because there are a lot of logical operators):
/*
message {Discord.Message}: the message you want to search in
target {string}: the string you're looking for
{
caseSensitive {boolean}: whether you want the search to be case case-sensitive
author {boolean}: whether you want to search in the author's name
description {boolean}: whether you want to search in the description
footer {boolean}: whether you want to search in the footer
title {boolean}: whether you want to search in the title
fields {boolean}: whether you want to search in the fields
}
*/
function findInMessage(message, target, {
caseSensitive = false,
author = false,
description = true,
footer = true,
title = true,
fields = true
}) {
if (!target || !message) return null;
let str = caseSensitive ? target : target.toLowerCase();
if ((caseSensitive && message.content.includes(str)) ||
(!caseSensitive && message.content.toLowerCase().includes(str))) return true;
for (let embed of message.embeds) {
if ((caseSensitive && (
(author && embed.author.includes(str)) ||
(description && embed.description.includes(str)) ||
(footer && embed.footer.includes(str)) ||
(title && embed.title.includes(str)))) ||
(!caseSensitive && (
(author && embed.author.toLowerCase().includes(str)) ||
(description && embed.description.toLowerCase().includes(str)) ||
(footer && embed.footer.toLowerCase().includes(str)) ||
(title && embed.title.toLowerCase().includes(str))))
) return true;
if (fields)
for (let field of embed.fields) {
if ((caseSensitive && [field.name, field.value].includes(str)) ||
(!caseSensitive && [field.name.toLowerCase(), field.value.toLowerCase()].includes(str))) return true;
}
}
return false;
}
The functions returns true
when finds the word you put in, false
when it doesn't find it and null
when one of the non-optional arguments is missing.
You can use it like this:
if (findInMessage(message, 'cyber')) message.channel.send("Key word detected.");
There are some instructions at the top, hope this helps ;)
answered Nov 8 at 16:52
Federico Grandi
2,4081926
2,4081926
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53201455%2fhow-to-get-discord-bot-to-read-embed%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It sounds like you're asking for SO to write code for you. Could you show what you've tried to change within those lines, and explain why it didn't work? Maybe link the part of the docs you're trying to deal with
– TankorSmash
Nov 8 at 5:30
I tried changing the code to look like
if(embed.Message.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected ");
if(embed.content.toLowerCase().includes('cyber')) message.channel.send("Key Word Detected ");
nothing seems to be working and everything I've looked up seems to not have any solution to my problem– Mark Farag
Nov 8 at 5:44
Are you sure that embed.Message exists ? For me, after looking at this guide, it seems like an embed is a list of fields, so I would do something like
fields = message.embed.fields; len = fields.length; for var i in range(len){ if fields[i].value.contains('cyber')...
– Djazouli
Nov 8 at 6:25