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

Badresource:Bad resource ID ERROR #27859

Open
nekodendislike opened this issue Jan 29, 2025 · 6 comments
Open

Badresource:Bad resource ID ERROR #27859

nekodendislike opened this issue Jan 29, 2025 · 6 comments
Assignees
Labels
needs investigation requires further investigation before determining if it is an issue or not node:http Issues with `node:http` module - to be fixed with a rewrite

Comments

@nekodendislike
Copy link

nekodendislike commented Jan 29, 2025

Version: Deno 2.1.7

import { ActionRowBuilder, ChannelType, EmbedBuilder, InteractionContextType, PermissionFlagsBits, ModalBuilder, SlashCommandBuilder, TextInputBuilder, TextInputStyle } from 'npm:discord.js';
import type { ChatInputCommandInteraction } from 'npm:discord.js';
import { entersState, AudioPlayerStatus, createAudioPlayer, createAudioResource, joinVoiceChannel, StreamType, NoSubscriberBehavior } from 'npm:@discordjs/voice';
import * as firestore from 'npm:firebase-admin/firestore';

import lang_match from '../../resource/localizations/lang.js';

const languageKey = "commands.join_stereo";

const sanka_embed = new EmbedBuilder()
   .setColor(0xEBD723)
   .setTitle(lang_match('ja', languageKey, 'embed_title_sucsess'))
   .setDescription(lang_match('ja', languageKey, 'embed_description_sucsess'))
   .setFooter({text: lang_match('common', 'embed', 'footer')})
export const data = new SlashCommandBuilder()
    .setName("joinstereo")
    .setDescription("指定したチャンネルに参加し、音楽を再生します。")
    .addChannelOption(option => option
        .setName('voice')
        .setDescription("参加するチャンネルを指定します。")
	.addChannelTypes(ChannelType.GuildVoice)
    )
    .setContexts(InteractionContextType.Guild)

export async function execute(interaction: ChatInputCommandInteraction, db: firestore.Firestore, stereoFiles){
    const serverId = interaction.guild!.id;
    const channelId = interaction.channel!.id;
        
    const vc = interaction.options.getChannel('voice');
	
	const connection = joinVoiceChannel({
		guildId: serverId,
		channelId: vc!.id,
		adapterCreator: interaction.guild!.voiceAdapterCreator,
		selfDeaf: true,
		selfMute: false
	});
	const player = createAudioPlayer({
        behaviors: {
            noSubscriber: NoSubscriberBehavior.Pause,
        },
    });

    connection.subscribe(player);
	const res = createAudioResource('../../resource/rakustereo/It_isnt_raining.mp3',{
		inputType: StreamType.Arbitrary
	});
	player.play(res);
		player.on(AudioPlayerStatus.Playing, () => {
			console.log('The audio is now playing!');
		});
		player.on(AudioPlayerStatus.Idle, () => {
			console.log('Playback has ended.');
			connection.destroy();
		});
	await interaction.reply({embeds: [sanka_embed]});

}; 

This code thrown an Error…

error: Uncaught (in promise) BadResource: Bad resource ID
    at node:http:306:27
    at HttpsClientRequest._writeHeader (node:http:398:7)
    at HttpsClientRequest._flushHeaders (node:_http_outgoing:
382:12)
    at TLSSocket.onConnect (node:http:444:16)
    at TLSSocket.emit (ext:deno_node/_events.mjs:405:35)
    at _afterConnect (node:net:159:12)
    at _afterConnectMultiple (node:net:214:3)
    at TCP.afterConnect (ext:deno_node/internal_binding/conne
ction_wrap.ts:43:11)
    at TCP.handle.afterConnect (node:_tls_wrap:157:29)
    at eventLoopTick (ext:core/01_core.js:175:7)
@littledivy littledivy added needs investigation requires further investigation before determining if it is an issue or not node:http Issues with `node:http` module - to be fixed with a rewrite labels Jan 29, 2025
@kimdcottrell
Copy link

kimdcottrell commented Jan 29, 2025

Oh my goodness I was just about to report this.

There's a npm package called ws that's used in some other npm packages (e.g. xrpl.js, discord.js) as the Websocket library.

@littledivy pinging you since you tagged this as "needs investigation" and maybe this comment will help you.

If you use it instead of the builtin WebSocket, it completely bombs out. Some test code:

deno@45ff7ae11a56:/app/src$ deno
Deno 2.1.7
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> import { WebSocket as socker } from 'npm:ws';

undefined
> const xrpl = new socker("wss://s.altnet.rippletest.net:51233/");

undefined
> 
undefined
Uncaught BadResource: Bad resource ID
    at node:http:312:27
    at HttpsClientRequest._writeHeader (node:http:404:7)
    at HttpsClientRequest._flushHeaders (node:_http_outgoing:382:12)
    at TLSSocket.onConnect (node:http:450:16)
    at TLSSocket.emit (ext:deno_node/_events.mjs:405:35)
    at TCPConnectWrap._afterConnect [as oncomplete] (node:net:159:12)
    at TCP.afterConnect (ext:deno_node/internal_binding/connection_wrap.ts:43:11)
    at ext:deno_node/internal_binding/tcp_wrap.ts:299:14
    at eventLoopTick (ext:core/01_core.js:177:7)

@nathanwhit
Copy link
Member

seems to have been fixed in #27792

Does upgrading to the latest canary version (which includes that fix) resolve the issue?

deno upgrade canary

@nekodendislike
Copy link
Author

seems to have been fixed in #27792

Does upgrading to the latest canary version (which includes that fix) resolve the issue?

deno upgrade canary

Deno upgrade canarydid not resolve the issue.

@kimdcottrell
Copy link

seems to have been fixed in #27792

Does upgrading to the latest canary version (which includes that fix) resolve the issue?

deno upgrade canary

This works for my use case with xrpl.js. I can now run at least some of the sample code. I'll rejoin this convo if the issue comes back as I play with this library.

@nathanwhit
Copy link
Member

cc @kt3k, seems to have been caused by #25470

@kt3k kt3k self-assigned this Jan 31, 2025
@kt3k
Copy link
Member

kt3k commented Jan 31, 2025

@nekodendislike Can you try it with Deno 2.1.4? (you can switch to 2.1.4 by deno upgrade --version 2.1.4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs investigation requires further investigation before determining if it is an issue or not node:http Issues with `node:http` module - to be fixed with a rewrite
Projects
None yet
Development

No branches or pull requests

5 participants