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










0















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









share|improve this question






















  • 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















0















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









share|improve this question






















  • 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













0












0








0








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









share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 21 at 16:37









Bhindley0404Bhindley0404

31




31












  • 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

















  • 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
















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












1 Answer
1






active

oldest

votes


















0














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
// ....






share|improve this answer























  • Thank you, the module works great now!

    – Bhindley0404
    Mar 22 at 16:03











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
);



);













draft saved

draft discarded


















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









0














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
// ....






share|improve this answer























  • Thank you, the module works great now!

    – Bhindley0404
    Mar 22 at 16:03















0














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
// ....






share|improve this answer























  • Thank you, the module works great now!

    – Bhindley0404
    Mar 22 at 16:03













0












0








0







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
// ....






share|improve this answer













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
// ....







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 21 at 16:41









doublesharpdoublesharp

19.6k33861




19.6k33861












  • 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





Thank you, the module works great now!

– Bhindley0404
Mar 22 at 16:03



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현