Cannot read property 'nsfw' of undefined - discord.js The Next CEO of Stack OverflowDetecting an undefined object propertyHow to check empty/undefined/null string in JavaScript?How can I merge properties of two JavaScript objects dynamically?How do I remove a property from a JavaScript object?Sort array of objects by string property valueHow to determine if variable is 'undefined' or 'null'?How to check for “undefined” in JavaScript?Is there a standard function to check for null, undefined, or blank variables in JavaScript?Iterate through object propertiesDiscord.js bot embeds using weighted random choice from an array
How easy is it to start Magic from scratch?
Are there languages with no euphemisms?
Natural language into sentence logic
India just shot down a satellite from the ground. At what altitude range is the resulting debris field?
Horror movie/show or scene where a horse creature opens its mouth really wide and devours a man in a stables
How to write papers efficiently when English isn't my first language?
Apart from "berlinern", do any other German dialects have a corresponding verb?
% symbol leads to superlong (forever?) compilations
Go Pregnant or Go Home
How to count occurrences of text in a file?
Only print output after finding pattern
Is it safe to use c_str() on a temporary string?
How to make a variable always equal to the result of some calculations?
Is it okay to store user locations?
Does it take more energy to get to Venus or to Mars?
Rotate a column
What is the point of a new vote on May's deal when the indicative votes suggest she will not win?
Which organization defines CJK Unified Ideographs?
How to write the block matrix in LaTex?
Why here is plural "We went to the movies last night."
Science fiction (dystopian) short story set after WWIII
MAZDA 3 2006 (UK) - poor acceleration then takes off at 3250 revs
Customer Requests (Sometimes) Drive Me Bonkers!
How do I solve this limit?
Cannot read property 'nsfw' of undefined - discord.js
The Next CEO of Stack OverflowDetecting an undefined object propertyHow to check empty/undefined/null string in JavaScript?How can I merge properties of two JavaScript objects dynamically?How do I remove a property from a JavaScript object?Sort array of objects by string property valueHow to determine if variable is 'undefined' or 'null'?How to check for “undefined” in JavaScript?Is there a standard function to check for null, undefined, or blank variables in JavaScript?Iterate through object propertiesDiscord.js bot embeds using weighted random choice from an array
I'm currently working on a discord bot that makes use of 'discord.js', 'discord.js-commando' and 'snekfetch'. I'm trying to create a function in which if a guild member were to type "!meme", the discord bot will grab a random post from r/dankmemes and send it to the respective channel using richEmbed. however, upon testing the function the following error messages appear:
TypeError: Cannot read property 'nsfw' of undefined
TypeError: Cannot read property 'send' of undefined
I've been trying to resolve the issue for 4 days and i'm utterly clueless as to what is causing this issue. According to the discord.js documentation this should work absolutely fine. I've attached the command module below:
const Commando = require('discord.js-commando');
const Discord = require('discord.js');
const snekfetch = require('snekfetch');
class MemesRssCommand extends Commando.Command
constructor(client)
super(client,
name: 'meme',
group: 'simple',
memberName: 'meme',
description: 'Takes a random meme from r/dankmemes'
);
async run(client, message, args)
try
const body = await snekfetch
.get('https://www.reddit.com/r/dankmemes.json?sort=top&t=week')
.query( limit: 800 );
const allowed = message.channel.nsfw ? body.data.children : body.data.children.filter(post => !post.data.over_18);
if (!allowed.length) return message.channel.send('Our farmers were unable to locate any ripe memes! Try again later (You shouldnt see this message. If you are reading this, then reddit is probably offline. If reddit is online and you still get this message, contact @𝕏𝕪𝕝𝕠𝕟𝕠𝕝𝕪#1612');
const randomnumber = Math.floor(Math.random() * allowed.length)
const embed = new Discord.RichEmbed()
.setColor(0x00A2E8)
.setTitle(allowed[randomnumber].data.title)
.setDescription("Posted by: " + allowed[randomnumber].data.author)
.setImage(allowed[randomnumber].data.url)
.addField("Other info:", "Up votes: " + allowed[randomnumber].data.ups + " / Comments: " + allowed[randomnumber].data.num_comments)
.setFooter("Posted by: " + allowed[randomnumber].data.author + " catch (err)
return console.log(err);
module.exports = MemesRssCommand
javascript discord.js commando
add a comment |
I'm currently working on a discord bot that makes use of 'discord.js', 'discord.js-commando' and 'snekfetch'. I'm trying to create a function in which if a guild member were to type "!meme", the discord bot will grab a random post from r/dankmemes and send it to the respective channel using richEmbed. however, upon testing the function the following error messages appear:
TypeError: Cannot read property 'nsfw' of undefined
TypeError: Cannot read property 'send' of undefined
I've been trying to resolve the issue for 4 days and i'm utterly clueless as to what is causing this issue. According to the discord.js documentation this should work absolutely fine. I've attached the command module below:
const Commando = require('discord.js-commando');
const Discord = require('discord.js');
const snekfetch = require('snekfetch');
class MemesRssCommand extends Commando.Command
constructor(client)
super(client,
name: 'meme',
group: 'simple',
memberName: 'meme',
description: 'Takes a random meme from r/dankmemes'
);
async run(client, message, args)
try
const body = await snekfetch
.get('https://www.reddit.com/r/dankmemes.json?sort=top&t=week')
.query( limit: 800 );
const allowed = message.channel.nsfw ? body.data.children : body.data.children.filter(post => !post.data.over_18);
if (!allowed.length) return message.channel.send('Our farmers were unable to locate any ripe memes! Try again later (You shouldnt see this message. If you are reading this, then reddit is probably offline. If reddit is online and you still get this message, contact @𝕏𝕪𝕝𝕠𝕟𝕠𝕝𝕪#1612');
const randomnumber = Math.floor(Math.random() * allowed.length)
const embed = new Discord.RichEmbed()
.setColor(0x00A2E8)
.setTitle(allowed[randomnumber].data.title)
.setDescription("Posted by: " + allowed[randomnumber].data.author)
.setImage(allowed[randomnumber].data.url)
.addField("Other info:", "Up votes: " + allowed[randomnumber].data.ups + " / Comments: " + allowed[randomnumber].data.num_comments)
.setFooter("Posted by: " + allowed[randomnumber].data.author + " catch (err)
return console.log(err);
module.exports = MemesRssCommand
javascript discord.js commando
As the error states,message.channel
isundefined
. Check the value of the second argument you pass intorun()
.
– Bucket
Mar 21 at 16:40
@Bucket the problem is thatrun
takes only two argumentsrun(message, args)
.
– doublesharp
Mar 21 at 16:42
add a comment |
I'm currently working on a discord bot that makes use of 'discord.js', 'discord.js-commando' and 'snekfetch'. I'm trying to create a function in which if a guild member were to type "!meme", the discord bot will grab a random post from r/dankmemes and send it to the respective channel using richEmbed. however, upon testing the function the following error messages appear:
TypeError: Cannot read property 'nsfw' of undefined
TypeError: Cannot read property 'send' of undefined
I've been trying to resolve the issue for 4 days and i'm utterly clueless as to what is causing this issue. According to the discord.js documentation this should work absolutely fine. I've attached the command module below:
const Commando = require('discord.js-commando');
const Discord = require('discord.js');
const snekfetch = require('snekfetch');
class MemesRssCommand extends Commando.Command
constructor(client)
super(client,
name: 'meme',
group: 'simple',
memberName: 'meme',
description: 'Takes a random meme from r/dankmemes'
);
async run(client, message, args)
try
const body = await snekfetch
.get('https://www.reddit.com/r/dankmemes.json?sort=top&t=week')
.query( limit: 800 );
const allowed = message.channel.nsfw ? body.data.children : body.data.children.filter(post => !post.data.over_18);
if (!allowed.length) return message.channel.send('Our farmers were unable to locate any ripe memes! Try again later (You shouldnt see this message. If you are reading this, then reddit is probably offline. If reddit is online and you still get this message, contact @𝕏𝕪𝕝𝕠𝕟𝕠𝕝𝕪#1612');
const randomnumber = Math.floor(Math.random() * allowed.length)
const embed = new Discord.RichEmbed()
.setColor(0x00A2E8)
.setTitle(allowed[randomnumber].data.title)
.setDescription("Posted by: " + allowed[randomnumber].data.author)
.setImage(allowed[randomnumber].data.url)
.addField("Other info:", "Up votes: " + allowed[randomnumber].data.ups + " / Comments: " + allowed[randomnumber].data.num_comments)
.setFooter("Posted by: " + allowed[randomnumber].data.author + " catch (err)
return console.log(err);
module.exports = MemesRssCommand
javascript discord.js commando
I'm currently working on a discord bot that makes use of 'discord.js', 'discord.js-commando' and 'snekfetch'. I'm trying to create a function in which if a guild member were to type "!meme", the discord bot will grab a random post from r/dankmemes and send it to the respective channel using richEmbed. however, upon testing the function the following error messages appear:
TypeError: Cannot read property 'nsfw' of undefined
TypeError: Cannot read property 'send' of undefined
I've been trying to resolve the issue for 4 days and i'm utterly clueless as to what is causing this issue. According to the discord.js documentation this should work absolutely fine. I've attached the command module below:
const Commando = require('discord.js-commando');
const Discord = require('discord.js');
const snekfetch = require('snekfetch');
class MemesRssCommand extends Commando.Command
constructor(client)
super(client,
name: 'meme',
group: 'simple',
memberName: 'meme',
description: 'Takes a random meme from r/dankmemes'
);
async run(client, message, args)
try
const body = await snekfetch
.get('https://www.reddit.com/r/dankmemes.json?sort=top&t=week')
.query( limit: 800 );
const allowed = message.channel.nsfw ? body.data.children : body.data.children.filter(post => !post.data.over_18);
if (!allowed.length) return message.channel.send('Our farmers were unable to locate any ripe memes! Try again later (You shouldnt see this message. If you are reading this, then reddit is probably offline. If reddit is online and you still get this message, contact @𝕏𝕪𝕝𝕠𝕟𝕠𝕝𝕪#1612');
const randomnumber = Math.floor(Math.random() * allowed.length)
const embed = new Discord.RichEmbed()
.setColor(0x00A2E8)
.setTitle(allowed[randomnumber].data.title)
.setDescription("Posted by: " + allowed[randomnumber].data.author)
.setImage(allowed[randomnumber].data.url)
.addField("Other info:", "Up votes: " + allowed[randomnumber].data.ups + " / Comments: " + allowed[randomnumber].data.num_comments)
.setFooter("Posted by: " + allowed[randomnumber].data.author + " catch (err)
return console.log(err);
module.exports = MemesRssCommand
javascript discord.js commando
javascript discord.js commando
asked Mar 21 at 16:37
Bhindley0404Bhindley0404
31
31
As the error states,message.channel
isundefined
. Check the value of the second argument you pass intorun()
.
– Bucket
Mar 21 at 16:40
@Bucket the problem is thatrun
takes only two argumentsrun(message, args)
.
– doublesharp
Mar 21 at 16:42
add a comment |
As the error states,message.channel
isundefined
. Check the value of the second argument you pass intorun()
.
– Bucket
Mar 21 at 16:40
@Bucket the problem is thatrun
takes only two argumentsrun(message, args)
.
– doublesharp
Mar 21 at 16:42
As the error states,
message.channel
is undefined
. Check the value of the second argument you pass into run()
.– Bucket
Mar 21 at 16:40
As the error states,
message.channel
is undefined
. Check the value of the second argument you pass into run()
.– Bucket
Mar 21 at 16:40
@Bucket the problem is that
run
takes only two arguments run(message, args)
.– doublesharp
Mar 21 at 16:42
@Bucket the problem is that
run
takes only two arguments run(message, args)
.– doublesharp
Mar 21 at 16:42
add a comment |
1 Answer
1
active
oldest
votes
According to the example in documentation the callback for run
is run(message, args)
but you are defining it as run(client, message, args)
, thus the message.channel
is undefined since you are trying to access it on the wrong object.
async run(message, args)
const member = args.member;
const channel = message.channel
// ....
Thank you, the module works great now!
– Bhindley0404
Mar 22 at 16:03
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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%2f55285241%2fcannot-read-property-nsfw-of-undefined-discord-js%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
According to the example in documentation the callback for run
is run(message, args)
but you are defining it as run(client, message, args)
, thus the message.channel
is undefined since you are trying to access it on the wrong object.
async run(message, args)
const member = args.member;
const channel = message.channel
// ....
Thank you, the module works great now!
– Bhindley0404
Mar 22 at 16:03
add a comment |
According to the example in documentation the callback for run
is run(message, args)
but you are defining it as run(client, message, args)
, thus the message.channel
is undefined since you are trying to access it on the wrong object.
async run(message, args)
const member = args.member;
const channel = message.channel
// ....
Thank you, the module works great now!
– Bhindley0404
Mar 22 at 16:03
add a comment |
According to the example in documentation the callback for run
is run(message, args)
but you are defining it as run(client, message, args)
, thus the message.channel
is undefined since you are trying to access it on the wrong object.
async run(message, args)
const member = args.member;
const channel = message.channel
// ....
According to the example in documentation the callback for run
is run(message, args)
but you are defining it as run(client, message, args)
, thus the message.channel
is undefined since you are trying to access it on the wrong object.
async run(message, args)
const member = args.member;
const channel = message.channel
// ....
answered Mar 21 at 16:41
doublesharpdoublesharp
19.6k33861
19.6k33861
Thank you, the module works great now!
– Bhindley0404
Mar 22 at 16:03
add a comment |
Thank you, the module works great now!
– Bhindley0404
Mar 22 at 16:03
Thank you, the module works great now!
– Bhindley0404
Mar 22 at 16:03
Thank you, the module works great now!
– Bhindley0404
Mar 22 at 16:03
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.
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%2f55285241%2fcannot-read-property-nsfw-of-undefined-discord-js%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
As the error states,
message.channel
isundefined
. Check the value of the second argument you pass intorun()
.– Bucket
Mar 21 at 16:40
@Bucket the problem is that
run
takes only two argumentsrun(message, args)
.– doublesharp
Mar 21 at 16:42