How can I change the volume of my discord bot in discord.js V13? - discord

I am creating a Discord Bot and I am getting along quite good, however, I am now trying to implement a command for changing the volume of the bot and I can't figure out how to do it. All I am finding on the Internet is for V12 or below, but I am using the new version of discord.js - V13. Here is what I have for playing the music:
const connection = await connect(channel);
const audioPlayer = createAudioPlayer();
const stream = createStream(song.url);
const resource = createAudioResource(stream, {
inputType: StreamType.Arbitrary,
});
stream.on('error', () => playQueue(guild, channel));
connection.subscribe(audioPlayer);
audioPlayer.play(resource);
This all works but does one of you know how to change the volume?
Side question:
I am also trying to make a /seek <time> to jump to any place in the video and neither am I making any progress with that.

I fixed it now, thanks to Leau:
The problem I had was that I was trying to set resource.volume to the value, whereas I actually would have had to do it via resource.volume.setVolume() with the #discordjs/opus package installed and the option on resource for inlineVolume set to true

Related

How to (and is it possible to) make link markup work in a discord bot message?

What I'm trying to achieve is simple:
send a message like links: [link1](https://example.com/1), [link1](https://example.com/2) via a bot
get it displayed as "links: link1, link1"
In a ephemeral follow up, it works as expected:
const content = "links: [link1](https://example.com/1), [link1](https://example.com/2)"
await interaction.followUp({
ephemeral: true,
content,
})
But when I send this to a public channel like this:
await channel.send(content)
I'm getting it as plain text (links: [link1](https://example.com/1), [link1](https://example.com/2)) except the links are clickable.
Is it possible to get the same result as in an ephemeral message?
I've checked the permissions, there's only "embed" links (which sounds like "allow links in embeds", and not "allow links in messages) and it is enabled anyway on server for everyone, for the bot and in the channel. So what am I missing here?
PS Here they say that "it's only possible if the message was sent with webhook though", but I'm not quite sure what does this mean (can this be different for a public and an ephemeral message?)
You cannot use hyper links in normal messages sent by a bot. You need to use a Webhook. Considering you're using discord.js, see this guide on their documentation. When using something like that it will work as expected
const { WebhookClient } = require('discord.js');
const webhookClient = new WebhookClient({ url: "WEBHOOK_URL" });
webhookClient.send({
content: "[Hello world](https://github.com)",
username: "Webhook Username",
});
Otherwise you may use embeds and send one of these with your bot and the content you wish to have.
Right, so I've found a solution based on suggestion by Krypton. As an embed doesn't look nice and manual creation of a webhook is not an option for me, I've found that I can create a webhook on the go and use it.
After some testing, I've figured that such webhooks are also permanent (although they can be found in another part of settings than the manually created ones); they should be deleted as there's a limit of 15 webhooks – an attempt to create more fails (with DiscordAPIError[30007]: Maximum number of webhooks reached (15)).
Instead of doing
await channel.send(content)
I've put
// a guard, TypeScript requires us to be sure
if(channel instanceof TextChannel) {
const webhook = await channel.createWebhook({
// a message from a webhook has a different sender, here we set its name,
// for instance the same as the name of our bot (likewise, we can set an avatar)
name: "MyBot",
})
await webhook.send(content)
await webhook.delete()
}
This seems to be a minimal code change to get the links working.

Discord.js - Delete all channel by running Discord-Bot without a command

Hey i need for a project a tool to delete all channsl on a Discordserver via a Discord.js Bot.
i got one with handlers and this is my "event code" but dosent work.
Discord.js v14
const client = require("../../index");
module.exports = {
name: "blacksheep"
};
client.on("ready", () => {
var server = Client.guilds.get('1045245227264397382');
for (var i = 0; i < server.channels.array().length; i++) {
server.channels.array()[i].delete();
}})
i dont find the right way to get it worked. thx <3
Then i start the bot all Channels should be deletet without any command.
You need to include error messages or what the results of running this code was for us to actually help you, but for now I'm going to assume that everything in your bot and bot event handlers is working except for the last three lines that loop through the channels and delete them. If that's the case, then you just need to change those lines to something like this (replace your for-loop block with this):
server.channels.cache.forEach((channel) => {
channel.delete();
});
This accesses the server's channel cache, which is a collection, and so it uses the collection's forEach function to loop through all the channels, and then calls each of the channels' delete() functions to delete them.
Note that you may experience severe ratelimiting when doing this, because Discord has heavy ratelimits on requests to server channels.

Discord Missing Intent Error on discord.js

Im having trouble launching my code for the past 6 hours it was working fine yesterday but it doesnt seem to work any more i keep on having an error that says ('CLIENT_MISSING_INTENT')
this is my starting code i dont understand what i am doing wrong
const Discord = require('discord.js'),
welcome = require('./welcome'),
mute = require('./mute'),
unmute = require('./unmute'),
mongoose = require('mongoose'),
Levels = require("discord-xp")
const { Client, Intents } = require("discord.js");
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});
You're quite literally missing an Intent. As you're probably already aware based on your code, v13 of discord.js requires you to add certain Intents to avoid processing power being thrown away to features not used.
You can look at all Intents available here, and try to add a few of them to see which one you need. Based on your code I can't see which one you're missing.

Is there anyway I can make a Discord js Bot that send an embed when a specific account in instagram posts

i just want it to send an embed or even just the link of the post when the account posts on Instagram. I tried the IFTTT website but they only let you do this for your own instagram account and i want it to do the above for another public account. Thenks.
I don't think that coding the entire project out for you would be useful, so I can give you some pointers:
For the Instagram scraping, I'd suggest using Nightmare, a high-level browser automation library. It's easy to use and quite powerful.
Here's what the start of your program should look like:
const Discord = require('discord.js');
const client = new Discord.Client();
const Nightmare = require('nightmare')
const nightmare = Nightmare({ show: true })
const accountName = 'insertaccountnamehere'
Nightmare({ show: false })
.goto(`https://www.instagram.com/${accountName}`)
// your turn
You would update some variable that keeps the newest post, check if it changed, and then send whatever you want: embed, link, so on.

Creating a Discord bot to notify people when to certain text on a website has changed

const Discord = require('discord.js');
const bot = new Discord.Client();
const token = '';
bot.on('ready', () =>{
console.log('This bot is online');
})
bot.on('message', msg=>{
if(msg.content === "?rates"){
msg.reply('.')
}
})
bot.login(token);
This is what I have so far it is very basic, I understand, I'm just trying to get some sort of idea how to process. What I want is as soon as a website gets updated or changed. I would like it to tag everyone and in a certain channel and specifies what has changed. I know this will be a long process but I'm in for the ride :) would appreciate any help.
You need a webhook on the website and listen to it with your bot, if you have control over the site, this may help you, otherwise you could look if the site has one or perhaps ask an owner.
A probably working but not very nice (and not very clean) solution would be to save the text of the website every 5 seconds or so and compare it to the previous save. If it changed, you notify the members through sending a message.

Resources