mctantwerp / Canvas-Student-Announcement-Discord-Bot

A discord bot linked with the Canvas Student API that gives the possibility to watch specific courses and embed posts when there are new announcements for these courses.
Apache License 2.0
28 stars 9 forks source link

.cs and .wl not working #2

Closed shawnshyguy closed 3 years ago

shawnshyguy commented 3 years ago

Hi, Just threw the node bot on my sever real quick, configured .env, but .cs and .wl commands just throw out errors. namely, for .cs:

Connected to the memory database.
(node:1412279) UnhandledPromiseRejectionWarning: TypeError: fields.flat is not a function
    at Function.normalizeFields (/mnt/media/Etc/canvas_bot/Canvas-Student-Announcement-Discord-Bot/node_modules/discord.js/src/structures/MessageEmbed.js:450:8)
    at MessageEmbed.addFields (/mnt/media/Etc/canvas_bot/Canvas-Student-Announcement-Discord-Bot/node_modules/discord.js/src/structures/MessageEmbed.js:266:42)
    at row.forEach (/mnt/media/Etc/canvas_bot/Canvas-Student-Announcement-Discord-Bot/commands/courses.js:65:30)
    at Array.forEach (<anonymous>)
    at Statement.db.all (/mnt/media/Etc/canvas_bot/Canvas-Student-Announcement-Discord-Bot/commands/courses.js:61:17)
    at Statement.replacement (/mnt/media/Etc/canvas_bot/Canvas-Student-Announcement-Discord-Bot/node_modules/sqlite3/lib/trace.js:25:27)
(node:1412279) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
Close the database connection.

and .wl:

Connected to the memory database.
(node:1412141) UnhandledPromiseRejectionWarning: TypeError: fields.flat is not a function
    at Function.normalizeFields (/mnt/media/Etc/canvas_bot/Canvas-Student-Announcement-Discord-Bot/node_modules/discord.js/src/structures/MessageEmbed.js:450:8)
    at MessageEmbed.setup (/mnt/media/Etc/canvas_bot/Canvas-Student-Announcement-Discord-Bot/node_modules/discord.js/src/structures/MessageEmbed.js:78:91)
    at new MessageEmbed (/mnt/media/Etc/canvas_bot/Canvas-Student-Announcement-Discord-Bot/node_modules/discord.js/src/structures/MessageEmbed.js:18:10)
    at embedLikes.map.e (/mnt/media/Etc/canvas_bot/Canvas-Student-Announcement-Discord-Bot/node_modules/discord.js/src/structures/APIMessage.js:166:40)
    at Array.map (<anonymous>)
    at APIMessage.resolveData (/mnt/media/Etc/canvas_bot/Canvas-Student-Announcement-Discord-Bot/node_modules/discord.js/src/structures/APIMessage.js:166:31)
    at TextChannel.send (/mnt/media/Etc/canvas_bot/Canvas-Student-Announcement-Discord-Bot/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:166:62)
    at Statement.db.all (/mnt/media/Etc/canvas_bot/Canvas-Student-Announcement-Discord-Bot/commands/watchlist.js:81:33)
    at Statement.replacement (/mnt/media/Etc/canvas_bot/Canvas-Student-Announcement-Discord-Bot/node_modules/sqlite3/lib/trace.js:25:27)
(node:1412141) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
Close the database connection.

and after running .ac and it working successfully, .wl now outputs this, and kills the task:

Watchlist command executed!
Connected to the memory database.
/mnt/media/Etc/canvas_bot/Canvas-Student-Announcement-Discord-Bot/node_modules/discord.js/src/structures/MessageEmbed.js:450
      .flat(2)
       ^

TypeError: fields.flat is not a function
    at Function.normalizeFields (/mnt/media/Etc/canvas_bot/Canvas-Student-Announcement-Discord-Bot/node_modules/discord.js/src/structures/MessageEmbed.js:450:8)
    at MessageEmbed.addFields (/mnt/media/Etc/canvas_bot/Canvas-Student-Announcement-Discord-Bot/node_modules/discord.js/src/structures/MessageEmbed.js:266:42)
    at data.forEach (/mnt/media/Etc/canvas_bot/Canvas-Student-Announcement-Discord-Bot/commands/watchlist.js:70:38)
    at Array.forEach (<anonymous>)
    at row.forEach (/mnt/media/Etc/canvas_bot/Canvas-Student-Announcement-Discord-Bot/commands/watchlist.js:68:26)
    at Array.forEach (<anonymous>)
    at Statement.db.all (/mnt/media/Etc/canvas_bot/Canvas-Student-Announcement-Discord-Bot/commands/watchlist.js:66:21)
    at Statement.replacement (/mnt/media/Etc/canvas_bot/Canvas-Student-Announcement-Discord-Bot/node_modules/sqlite3/lib/trace.js:25:27)

Not sure what's wrong, looking for help. Running Ubuntu Server 20.04.1 LTS.

NoahNxT commented 3 years ago

Could you give us an example of your .env? Probably there is a misconfiguration, I've tried to reproduce your issue on Ubuntu Server 20.04.1 LTS but there were no issues.

NoahNxT commented 3 years ago

Here is an example of a .env (these keys are not working)

DISCORD_TOKEN='ODE3NDQwOGDJ4Tk4OTU5NjM2.YEJjIg.ep5J-w7cWAtzHDBFPOI2cn6CQvg' CANVAS_TOKEN='12400~D67ZKLzQJSODKEH3NpyEfoHzH6Nez00f9BfnazB6IDks9jVxniQPxsii13zvsXEM'

CANVAS_API_COURSES_URL='https://**canvas.testschool.com**/api/v1/courses?enrollment_state=active&access_token=**12400~D67ZKLzQJSODKEH3NpyEfoHzH6Nez00f9BfnazB6IDks9jVxniQPxsii13zvsXEM' CANVAS_API_COURSE_URL='https://canvas.testschool.com/api/v1/courses/[courseid]?access_token=12400~D67ZKLzQJSODKEH3NpyEfoHzH6Nez00f9BfnazB6IDks9jVxniQPxsii13zvsXEM' CANVAS_API_ANN_URL='https://canvas.testschool.com/api/v1/announcements?contextcodes[]=course[courseid]&access_token=12400~D67ZKLzQJSODKEH3NpyEfoHzH6Nez00f9BfnazB6IDks9jVxniQPxsii13zvsXEM**'

The bold parameters are the ones that you have to fill in, also the CANVAS_TOKEN value has to be the same as the access token in : CANVAS_API_COURSES_URL, CANVAS_API_COURSE_URL, CANVAS_API_ANN_URL

shawnshyguy commented 3 years ago

here's my .env:

fill everything in between <loremipsum>

DISCORD_TOKEN='ODIyMz...'
CANVAS_TOKEN='18471~vyK1F...' 

CANVAS_API_COURSES_URL='https://xxxxxpublicschools.instructure.com/api/v1/courses?enrollment_state=active&access_token=18471~vyK1F...'
CANVAS_API_COURSE_URL='https://xxxxxpublicschools.instructure.com/api/v1/courses/[courseid]?access_token=18471~vyK1F...'
CANVAS_API_ANN_URL='https://xxxxxpublicschools.instructure.com/api/v1/announcements?context_codes[]=course_[courseid]&access_token=18471~vyK1F...'
NoahNxT commented 3 years ago

Did you install all your npm modules with npm install? Which version of node are you using?

Here is a reference of an issue with the same error --> https://stackoverflow.com/questions/60934727/discord-js-messageembed-fields-flat-is-not-a-function --> https://github.com/discordjs/discord.js/issues/3910

image In de docs of discordJS is also described that version 12 of DiscordJS requires Node 12.0 or higher.

shawnshyguy commented 3 years ago

Hey, this seemed to fix it! Could've sworn I was running a newer version of node, but I was still on v10. Anyways, thanks for your help, it seems to be all good now.