Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Channel ID not being read from .env : Ubuntu Oracle Cloud hosted service #125

Open
welpdnd opened this issue Jun 9, 2024 · 19 comments
Open

Comments

@welpdnd
Copy link

welpdnd commented Jun 9, 2024

Hi,

Thanks for writing this up, much appreciated.

I've managed to get this working on a free Oracle Cloud VM. Unfortunately on npm run dev I get the error below. It appears to be trying to use a different channel ID to the one I input to the config file - even changing it to a dummy value has it revert to the channel ID below. I have tried to search for references to the channel ID below but no luck.

Server is running on port 5000
06-09 16:19:25 Logged in as GitHubIssues#6541!
06-09 16:19:25 Issues loaded : 7
/home/ubuntu/discordBot/node_modules/@discordjs/rest/src/lib/handlers/Shared.ts:148
                        throw new DiscordAPIError(data, 'code' in data ? data.code : data.error, status, method, url, requestData);
                              ^


DiscordAPIError[10003]: Unknown Channel
    at handleErrors (/home/ubuntu/discordBot/node_modules/@discordjs/rest/src/lib/handlers/Shared.ts:148:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at SequentialHandler.runRequest (/home/ubuntu/discordBot/node_modules/@discordjs/rest/src/lib/handlers/SequentialHandler.ts:417:20)
    at SequentialHandler.queueRequest (/home/ubuntu/discordBot/node_modules/@discordjs/rest/src/lib/handlers/SequentialHandler.ts:169:11)
    at _REST.request (/home/ubuntu/discordBot/node_modules/@discordjs/rest/src/lib/REST.ts:210:20)
    at async ChannelManager.fetch (/home/ubuntu/discordBot/node_modules/discord.js/src/managers/ChannelManager.js:123:18) {
  requestBody: { files: undefined, json: undefined },
  rawError: { message: 'Unknown Channel', code: 10003 },
  code: 10003,
  status: 404,
  method: 'GET',
  url: 'https://discord.com/api/v10/channels/1249342558606332075'

@welpdnd welpdnd changed the title Channel ID not being read from config file: Ubuntu Oracle Cloud hosted service Channel ID not being read from .env : Ubuntu Oracle Cloud hosted service Jun 9, 2024
@holmityd
Copy link
Owner

Hi

I've updated the readme to include instructions for retrieving the channel ID for the .env file here. Now, there are no placeholder values for the channel ID, ensuring that it's fetched directly from the .env file during runtime.

Let me know if you need further clarification or assistance

@holmityd
Copy link
Owner

image
https://discord.com/channels/<GUILD_ID>/<DISCORD_CHANNEL_ID>

@welpdnd
Copy link
Author

welpdnd commented Jun 10, 2024

Thank you for taking the time to investigate, respond and update so quickly, I really appreciate it - I spent about 5 hours trying all sorts to get it to work yesterday!

Unfortunately even with the new build I am still getting the same error with the same incorrect channel ID being used. It seems to be similar to what this user is reporting in: https://stackoverflow.com/questions/69218176/env-file-not-updating-in-local-environment-in-react-js

It seems like my local node installation might be faulty or have a broken cache. Even after reinstalling and purging any local node data, I am getting the same error message. I am pretty sure it is a local or user issue but if you have any other suggestions to troubleshoot, that would be great, otherwise I'll update this ticket with any progress.

@welpdnd
Copy link
Author

welpdnd commented Jun 10, 2024

Here's an example. The Discord token is picked up fine and the bot appears online locally but the wrong channel ID is being used, somehow! The ID on the right hand side is the correct one.
channelid

@holmityd
Copy link
Owner

holmityd commented Jun 10, 2024

src/discord/discordHandlers.ts after line 46

logger.info(`Issues loaded : ${store.threads.length}`);

add

console.log("DISCORD_CHANNEL_ID", config.DISCORD_CHANNEL_ID);

then run dev, before error must log id
image

@welpdnd
Copy link
Author

welpdnd commented Jun 10, 2024

Thanks for looking into this. Let me know if you have a tip jar link somewhere for a small thank you for your time.

The log outputs the correct channel ID, which indicates the .env file is being used correctly, but the script still uses the incorrect value on the GET. I have no idea what to think at this point 😄 . I tried deleting and recreating the bot, Discord server, channel, tokens etc. just in case that channel ID was encoded somewhere but I got the same result.

Screenshot 2024-06-10 133717

@holmityd
Copy link
Owner

holmityd commented Jun 10, 2024

if id same in .env file then idk, maybe bot dont have rights to see this channel, kick bot, reinvite with admin access link
https://discord.com/developers/applications/

image

@welpdnd
Copy link
Author

welpdnd commented Jun 10, 2024

Cheers, attempted all that and got the same error unfortunately.

The issue appears to be that the GET request is pointing to a channel ID that does not exist. It's possible this was the very first channel ID I used on my local system which has now been cached somewhere. The fact it is so persistent on a single variable is very confusing 😄 I can change the other variables (Discord token, GitHub token etc.) and have them update fine.

I will try this on a different PC or VM and see if it makes any difference.

@holmityd
Copy link
Owner

comment that part:
image

and try create new thread, if logs in terminal then good, if nothing happens then

@holmityd
Copy link
Owner

holmityd commented Jun 10, 2024

src/discord/discordHandlers.ts after line 53 add

console.log("handleThreadCreate", params.parentId);

image

after that on every new thread create will log channel id

image

1st id comes from .env file
2nd from discord bot when creating new thread, or even creating new msg in other channels, so check in not busy server

@welpdnd
Copy link
Author

welpdnd commented Jun 10, 2024

Thanks. Unfortunately the script is still erroring at the same stage so the event for the handeThreadCreate log item never appears. The correct thread ID is being gathered from .env but the incorrect ID is being used to call the Discord API.
Screenshot 2024-06-10 160111

It persists regardless of where I run it on my local machine, and even remotely on my VM. I figure I am incorrectly using the code - though I did manage to get it working at the start!

I am wondering if I should try to hard code my Discord channel ID in the ts scripts themselves? Then at least I can try to force it to point to the right location.

@holmityd
Copy link
Owner

Something wrong with terminal, its calling for someother channel_id, maybe kill all tasks (or just restart). And edited code part not same as in terminal i think, change console.log("DISCORD_CHANNEL_ID" to something else, for example console.log("TEST_DISCORD_CHANNEL_ID", guessing that from commented part, cus only this pa
rt fetching channel id which causing that error. But in pic channel ids different, idk where they comes from, they must be same

Безымянный

@holmityd
Copy link
Owner

comment that part too:
image

@holmityd
Copy link
Owner

if after that works, clear all issues on github issues page, and restore all changes

@holmityd
Copy link
Owner

yep, reproduced problem: github issue created with bot, bot turned off, discord thread deleted, github issue still there, code fetching all issues with regex /https://discord.com/channels/(\d+)/(\d+)/(\d+)(?=))/ , then tryes to sync with discord thread part, but its not there so gives error, my bad, didn't see on prev pic ids not same

@welpdnd
Copy link
Author

welpdnd commented Jun 10, 2024

comment that part too: image

This worked!
Screenshot 2024-06-10 172029

threadid

@holmityd
Copy link
Owner

yep, for now solution clear all github issues which created by bot, and dont delete post in discord without deleting it from github (bot will auto do that, but if off need manually delete), later will fix that to skip that issues while listing

@welpdnd
Copy link
Author

welpdnd commented Jun 10, 2024

Thank you so much for all your time today, this will be a huge benefit to my team. If you have a tip jar then just let me know!

@holmityd
Copy link
Owner

nah, you welcome, thanks for reporting that bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants