Hello lately ive been developing a music bot on discord and i got it to join and leave perfectly but playing music is just annoying and some reason play and playStream doesnt work. With the bot i would like a person to message the name of a song and it'll get a url out of it but each time is says no video id found here is my code;
client.on("message", (message) => {
if (message.content.startsWith(">p")){
let string = message.content;
let lastWord = string.slice(2);
if (lastWord != ">p"){
const {joinVoiceChannel} = require('#discordjs/voice')
const voice = require('#discordjs/voice')
const connection = joinVoiceChannel({
channelId: message.member.voice.channel.id,
guildId: message.member.guild.id,
adapterCreator: message.member.guild.voiceAdapterCreator
})
const stream = ytdl(lastWord, {filter: 'audioonly', quality: 'highestaudio'})
stream.pipe(fs.createWriteStream('tmp_buf_audio.mp3')).on('end', () => {
connection.playStream(fs.createReadStream('tmp_buf_audio.mp3'))
}
)};
}
});
here is also the error i get;
/home/runner/Bot-Project/node_modules/ytdl-core/lib/url-utils.js:63
throw Error(`No video id found: ${str}`);
^
Error: No video id found:
at Object.exports.getVideoID (/home/runner/Bot-Project/node_modules/ytdl-core/lib/url-utils.js:63:11)
at Function.exports.<computed> [as getInfo] (/home/runner/Bot-Project/node_modules/ytdl-core/lib/info.js:484:29)
at ytdl (/home/runner/Bot-Project/node_modules/ytdl-core/lib/index.js:19:8)
at Client.<anonymous> (/home/runner/Bot-Project/index.js:83:16)
at Client.emit (node:events:402:35)
at Client.emit (node:domain:475:12)
Hint: hit control+c anytime to enter REPL.
Project is running!
(node:7809) DeprecationWarning: The message event is deprecated. Use messageCreate instead
(Use `node --trace-deprecation ...` to show where the warning was created)
Hint: hit control+c anytime to enter REPL.
Project is running!
(node:7923) DeprecationWarning: The message event is deprecated. Use messageCreate instead
(Use `node --trace-deprecation ...` to show where the warning was created)
/home/runner/Bot-Project/node_modules/ytdl-core/lib/url-utils.js:63
throw Error(`No video id found: ${str}`);
^
Error: No video id found: let it go
at Object.exports.getVideoID (/home/runner/Bot-Project/node_modules/ytdl-core/lib/url-utils.js:63:11)
at Function.exports.<computed> [as getInfo] (/home/runner/Bot-Project/node_modules/ytdl-core/lib/info.js:484:29)
at ytdl (/home/runner/Bot-Project/node_modules/ytdl-core/lib/index.js:19:8)
at Client.<anonymous> (/home/runner/Bot-Project/index.js:83:16)
at Client.emit (node:events:402:35)
at Client.emit (node:domain:475:12)
at MessageCreateAction.handle (/home/runner/Bot-Project/node_modules/discord.js/src/client/actions/MessageCreate.js:34:18)
at Object.module.exports [as MESSAGE_CREATE] (/home/runner/Bot-Project/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/runner/Bot-Project/node_modules/discord.js/src/client/websocket/WebSocketManager.js:351:31)
Emitted 'error' event on PassThrough instance at:
repl process died unexpectedly: exit status 1
I see you are using node-ytdl-core. The usage of ytdl('.....'), is wrong, it should be instead used as following : ytdl(url, [options]).
Go through https://www.npmjs.com/package/ytdl-core
Related
Ive tries some different things to make this work but it's not wanting to work
so am basicly trying to check someones custom status for a specific thing if there is for example .gg/test in it and give them a role than
My code
client.on('presenceUpdate', async (oldPresence, newPresence) => {
const role = newPresence.guild.roles.cache.get("927284722059595828");
const member = newPresence.member
const activities = member.user.presence.activities[0];
if (activities && (activities.state.includes( ".gg/test" ) || activities.state.includes("discord.gg/test" ))) {
return newPresence.member.roles.add(role)
} else {
if(member.roles.cache.get(role.id)) {
newPresence.member.roles.remove(role)
}
}
})
so can anyone correct the code to the correct format
and if possable make this multi server usable with a command thanks
the error i get
TypeError: Cannot read properties of undefined (reading 'id')
at Client.<anonymous> (/root/raegay2/boy.js:19:36)
at Client.emit (node:events:390:28)
at PresenceUpdateAction.handle (/root/raegay2/node_modules/discord.js/src/client/actions/PresenceUpdate.js:39:19)
at Object.module.exports [as PRESENCE_UPDATE] (/root/raegay2/node_modules/discord.js/src/client/websocket/handlers/PRESENCE_UPDATE.js:4:33)
at WebSocketManager.handlePacket (/root/raegay2/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/root/raegay2/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/root/raegay2/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/root/raegay2/node_modules/ws/lib/event-target.js:132:16)
at WebSocket.emit (node:events:390:28)
at Receiver.receiverOnMessage (/root/raegay2/node_modules/ws/lib/websocket.js:825:20)
I just tested your code and it worked fine. Did you enable Presence Intent on your bots discord developer page? If you are using Gateway Intents, you must specify the GUILD_PRESENCES intent in order to receive Presence Update events.
I am in the process of making a bot that has features that only work on a specific server. The server is about trading cards, and I want to make a bot that can moderate the server, and that people can have fun with.
The error looks like this:
c:\Users\REDACTED\Desktop\Sky\index.js:10
if (message.content === 'sky claim') {
^
ReferenceError: message is not defined
at Client.<anonymous> (c:\Users\kelly\Desktop\Sky\index.js:10:3)
at Client.emit (events.js:327:22)
at MessageCreateAction.handle (c:\Users\REDACTED\Desktop\Sky\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (c:\Users\REDACTED\Desktop\Sky\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (c:\Users\REDACTED\Desktop\Sky\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (c:\Users\REDACTED\Desktop\Sky\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (c:\Users\REDACTED\Desktop\Sky\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (c:\Users\REDACTED\Desktop\Sky\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:315:20)
at Receiver.receiverOnMessage (c:\Users\REDACTED\Desktop\Sky\node_modules\ws\lib\websocket.js:845:20)
The code for my Discord bot is here.
client.on("message", (msg) => {
if (message.content === "sky claim") {
message.channel.send("${message.author} claimed 250 SkyBucks. Spend SkyBucks on colored roles.");
console.log("${message.author} executed command successfully");
}
});`
I only added the part of the code that was giving the error.
If you read your error you should be able to find out why it doesn’t work:
client.on('message', message => {
if (message.content === 'sky eBay') {
message.channel.send('Our eBay store is #CollectAmazing, I will drop a link:');
message.channel.send('https://www.ebay.com/str/collectamazing');
}
})
Change all of the client.on('message', msg to client.on('message', message
I'm trying to make a ticket bot, but I'm not sure what is wrong with my !new command. Please help. I'm using what discord has in their docs The code is below.
const Discord = require('discord.js');
module.exports.run = async (bot, message, args) => {
message.react('✅');
let modrole = message.guild.roles.cache.find(r => r.name === 'Staff');
if (!modrole) {
console.log('Err: ModRole Not Found');
}
message.reply(`${message.author.username}#${message.author.discriminator}`);
message.guild.createChannel(`${message.author.username}#${message.author.discriminator}`, {
parent: '',
topic: message.author.id,
type: '',
permissionOverwrites: [
{ id: message.guild.id, deny: ['VIEW_CHANNEL'] },
{ id: modrole.id, allow: ['VIEW_CHANNEL', 'SEND_MESSAGES'] },
{ id: message.author.id, allow: ['VIEW_CHANNEL', 'SEND_MESSAGES'] }
]
}).then(c => {
message.reply(`, <#Staff>`)
const embed = new Discord.message.embed()
.setTitle('**New Ticket**')
.setDescription(`Thank you for opening a ticket *<#${message.author.id}>, a staff member will be with you shortly!`)
})
}
//name this whatever the command name is.
module.exports.help = {
name: "new"
}
These are the errors:
(node:1664) UnhandledPromiseRejectionWarning: TypeError: message.guild.createChannel is not a function
at Object.module.exports.run (C:\Users\8fwbu\Desktop\CodeTProj\Molten Dev\commands\new.js:20:19)
at Client.<anonymous> (C:\Users\8fwbu\Desktop\CodeTProj\Molten Dev\main.js:42:31)
at Client.emit (events.js:315:20)
at MessageCreateAction.handle (C:\Users\8fwbu\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\8fwbu\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\8fwbu\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\8fwbu\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\8fwbu\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\8fwbu\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:315:20)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1664) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1664) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Chances are you're not running Discord.js V11. If you installed Discord.js using the following command (Or updated it using the same command)
npm install discord.js
You're working on Discord.js V12. In Discord.js V12, <Guild>.createChannel is not a function. Instead, you'll use <Guild>.channels.create(). If you wish to return to Discord.js V11, you can use this command. This will overwrite the current Discord.js package with the most recent Discord.js V11 update.
npm install discord.js#11
The #11 indicates that you want V11, not V12.
Additionally, I would like to point out that putting a hashtag (#) in the title is not recommended or allowed by Discord. The channel will be created, except the hashtag will be excluded from the channel name which will result in something like this: User#0000 => #user0000. Also keep in mind that certain unicode characters are prohibited from Discord and will not be accepted.
CODE IS BELOW
I have a simple discord bot and added a message file under events--guild
module.exports = (Discord, client, message) => {
const prefix = '!';
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const cmd = args.shift().toLowerCase();
const command = client.commands.get(cmd);
if(command) commmand.execute(client, message, args, Discord);
}
```
Just Incase You need it here is my main file
```
const Discord = require('discord.js');
const client = new Discord.Client();
client.commands = new Discord.Collection();
client.events = new Discord.Collection();
['command_handler', 'event_handler'].forEach(handler =>{;
require(`./handlers/${handler}`)(client, Discord)
})
client.login('My Token');
full error below
TypeError: Cannot read property 'content' of undefined
at Object.module.exports (E:\Software\Discord Bots\BombBot\events\guild\message.js:3:17)
at Client.emit (events.js:315:20)
at MessageCreateAction.handle (E:\Software\Discord Bots\BombBot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (E:\Software\Discord Bots\BombBot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (E:\Software\Discord Bots\BombBot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (E:\Software\Discord Bots\BombBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (E:\Software\Discord Bots\BombBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (E:\Software\Discord Bots\BombBot\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:315:20)
About: this discord bot is a simple bot that I am trying do with a command and event handler as I am new to discord js and not to javascript, I tried to see if there was a few issues, but couldn't find any. The debug window can't help either because its a value/variable that shows as undefined but is defined above.
as I am a bit new I used the tutorial: https://www.youtube.com/watch?v=Sihf7B8D4Y8 and rewrote the code multiple times. If you have an idea please tell me before I rewrite it again.
The Debugger is below
E:\Software\node JS\node.exe .\index.js
BOT Is ONLINE
events/client/ready.js:4
Uncaught TypeError: Cannot read property 'content' of undefined
No debugger available, can not send 'variables'
Process exited with code 1
It's hard to determine the origin of the error based on the info you provided.
The message content is not guaranteed. Messages from other bots that are embeds have no content, thus it's undefined. To fix this, add Optional Chaining in your condition:
if(!message.content?.startsWith(prefix) || message.author.bot) return;
If that doesn't work, that probably means your message object is not Discord Message at all. Make sure you pass the arguments to your function correctly.
I am trying to make a discord bot send a message to a specific discord server using the servers id, I do not know the command for it, I tried something like this but it didn't work, I get an error, please help, thanks in advance!
My code
const Discord = require('discord.js');
const bot = new Discord.Client();
module.exports = {
name: "inviteme",
description: "inviteme",
execute(message, args){
var server = bot.guilds.get("serverid");
var channel = server.channels.get("channelid");
bot.guilds.forEach(guild => {
guild.channels.first().createInvite()
.then(inv => message(channel).send(`${guild.name} | ${inv.url}`));
});
}
}
The error
TypeError: Cannot read property 'channels' of undefined
at Object.execute (d:\etc\Discord Bots\Coinflip\commands\inviteme.js:10:30)
at Client.<anonymous> (d:\etc\Discord Bots\Coinflip\index.js:31:42)
at Client.emit (events.js:210:5)
at MessageCreateHandler.handle (d:\etc\Discord Bots\Coinflip\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketPacketManager.handle (d:\etc\Discord Bots\Coinflip\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:105:65)
at WebSocketConnection.onPacket (d:\etc\Discord Bots\Coinflip\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (d:\etc\Discord Bots\Coinflip\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
at WebSocket.onMessage (d:\etc\Discord Bots\Coinflip\node_modules\ws\lib\event-target.js:120:16)
at WebSocket.emit (events.js:210:5)
at Receiver.receiverOnMessage (d:\etc\Discord Bots\Coinflip\node_modules\ws\lib\websocket.js:789:20)
The problem is that bot.guilds.get("serverid"); will try to fetch the guild from a logged-in bot's cache - but in this file, you have bot set to new Discord.Client(); and never logged in.
Do not log in multiple bot instances. Instead, what you need to do is grab your already logged in bot instance from the message object passed to your command, like this: message.client.guilds.get("serverid") - basically, use message.client instead of bot, or put let bot = message.client; at the beginning of the execute function.