Discord.js - Bot join command author Voice Channel - discord.js

I am making a discord.js bot and i want that the bot join the voice channel of the command author. My code its actually this:
client.on("message", (message) => {
if (message.content.startsWith(prefix + "join")){
const vchannel = message.member.voiceChannel
vchannel.join()
}
});
Im using Discord.js Ver. 11 and when i run the bot and execute the command it says: Cannot read property "join"

Instead of using message.member.voiceConnection or message.member.voiceChannel, i recently learned this:
if (message.content.startsWith(prefix + "join")){
const { voiceChannel } = message.member;
if (!voiceChannel) {
return message.reply('please join a voice channel first!');
}
voiceChannel.join()
}
And, of course, please look at discord.js guide if you haven't allready. If you need help, just refer to it in most cases. They have a tut for a music bot which is really simple (no queue) but teaches you how to play music.
It worked for me, I'm guessing it should work for you.

So the property member of the class Message has no property voiceChannel.
You should instead do this:
let voiceChannel = message.member.voice.channel;
if (!voiceChannel){return message.reply(' Please join a voice channel first!');}
voiceChannel.join();
source: https://discord.js.org/#/docs/main/stable/general/welcome

Related

(Discord selfbot) Is there anyway to response if 'hi' in someone message

Is there anyway to make the selfbot response 'hello' if 'hi' is in someone message?
Like
A: hi? Anyone here?
The bot: hello
The bot response because 'hi' is in A's message.
I think it's not possible because i tried many Discord selfbot library and none of library work (Python)
Which library are you using?
I made a discord bot with discord.js (Javascript), and with that you can receive an event every time someone talks in your discord server and then respond depending on the contents of the message.
First you start your discord client (the Intents may vary depending on what you want to do):
const discordClient = new Client({ intents: [Intents.FLAGS.DIRECT_MESSAGES, Intents.FLAGS.GUILD_MESSAGES] })
Then the idea is to get the content of every new message and answer properly, once you have created your discord client, you will need to set up an event listener like this one:
discordClient.on('messageCreate', message => {
const content = messageReceived.content.toLocaleLowerCase()
if (content === 'hi') {
messageReceived.channel.send("hello, I'm a bot!")
}
})
And don't forget to login with your discord bot key
const discordKey = "YOUR DISCORD BOT KEY"
discordClient.login(discordKey)
You can also see the repository for my bot here.
And for your use case you would want to mainly focus on some parts insid discord.ts.
Hopefully this helps.
Here are some basic examples using discord.js within node.js.
Simple Response
To send a response, simply check if the user's message contains the desired input you want your bot to respond to.
if(message.content.toLowerCase().includes("ping") {
message.reply("Pong!")
}
Multiple Responses
This is a much more efficient method of responding to multiple inputs. This includes using an array.
const array = [
"hello",
"hola",
"bonjour"
]
if(array.some(word => message.content.toLowerCase().includes(`${word}`)) {
message.reply("Hello!")
}
Here's the code
---Starts From Here:---
// type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
// Only respond to messages containing "hi", "hey", "hello", or "sup"
if (context.params.event.content.match(/hi|hey|hello|sup/i)) {
let messageContent = context.params.event.content.match(/hi|hey|hello|sup/i);
await lib.discord.channels['#0.3.0'].messages.create({
channel_id: context.params.event.channel_id,
content: `${messageContent[0]} to you too 👋`,
message_reference: {
message_id: context.params.event.id
}
});
}
--Ends--
Image of code
I suggest using autocode.com it will really help you in coding life. I use it myself.
Here's a small guide https://autocode.com/guides/how-to-build-a-discord-bot/
If your banned using discord selfbot, that's not my fault
from discord.ext import commands
client = commands.Bot(
command_prefix='-',
self_bot=True,
help_command=None
)
#client.event
async def on_message(message):
if message.author == client.user:
return
if message.content == 'Hello!':
await message.channel.send("Hi how your day!")
client.run('user token', bot=False)

How do I make my Discord bot check if a member is in a voice channel when running the join command?

I am currently working on a music discord bot that I have been working on for a while now, but I couldn't seem to figure out how to get my bot to join the voice channel. So, I have completely erased everything, and I am starting from scratch. I have managed to code part of the bot, but I have run into an issue. That issue is that I don't quite seem to know how to make the music bot check to see if the author of the command is in a voice channel.
My code for my music bot.:
You are already checking if the member is in a voice channel line 18.
And to join a voice channel you can use the VoiceChannel.join() method
if (msg.content.toLowerCase() === "+join") {
if (msg.member.voice.channel) {
msg.member.voice.channel.join();
msg.channel.send("Successfully joined the voice channel");
} else return message.channel.send("Please join a voice channel first");
}

How to make my discord bot only work in a chat?

I am using discord.js to implement a bot in the discord. When I use a command in any channel in my server, my bot responds to it, but I would like that my bot only worked if someone was sending the commands inside a private chat with the bot, how do I do that?
If you only want it to work between DMs, do
if (!message.channel.type == `dm`) return;
//other commands
You can check if the message was sent in a certain channel by checking the Message.channel.id property.
client.on("message", message => {
if (message.channel.id !== "ChannelID") return false;
// Execute your commands here
});

Discord.js moving person to random VoiceChannel

I'm making a discord bot that will has a feature to move user's to a random voice channel if they want. I searched the internet 3 hours straight and checked the whole documentation. But still can't find anything.
note : I know this bot idea looks useless. But that's what I need.
code :
let voiceChannels = message.guild.filter(g => **idk how to check if it's vc** );
that's what I just found in 3 hours.
You'd need to access the guild's channels and then choose a random channel of type voice.
So in your case, it'd be:
let voiceChannel = message.guild.channels.cache.filter((channel) => channel.type === "voice").random();
if (!message.member.voice.channel) return message.reply("User is not in a voice channel");
await message.member.voice.setChannel(voiceChannel);

How to create a discord bot that only allows a specific word in a certain text channel

I am trying to create a discord bot that only allows the word "upgrade" in a certain text channel.
As I am very new to this I would like to learn about how this is done.
Its easy. First create a bot. I guess you know about node.js if not, find tutorials for creating a project with discord.js.
First create a client:
const Discord = require("discord.js");
const client = new Discord.Client();
client.login("SuperSecretBotTokenHere");
(make sure you have a bot token) discordapp.com/developers
Then you create a message event:
client.on("message", (message) => {
if(message.content != "upgrade") return message.delete()
});
Put your bot in the server, give it permissions to delete messages in the channel aaand done!
Sorry for my bad English.

Resources