message.channel.awaitMessages() not working? | Discord.js V14 - discord.js

I resurrected a bot I had from a while ago but can get it to read Dm responses in Discordjs V14.
I have DirectMessages intents specified, It will send the Question via DM but not react to a response.
await appChannel.send('Name?');
let answer1 = await appChannel.awaitMessages(answer1 => answer1.author.id != client.user.id, { max: 1 });
const name = (answer1.map(answers => answers.content).join());
I Have a series of questions that then get posted to a discord channel using MessageEmbed()

Related

Discord JS - If user sends DM to bot with specific string

The code below works and send a DM to the user when he/she reacts to a message.
The goal is then to add a role - or do something - if the user replies with the correct string.
if (reaction.emoji.name === theDoor) {
await reaction.message.guild.members.cache.get(user.id).roles.add(treasure);
const reactUser = await reaction.message.guild.members.cache.get(user.id);
reactUser.send('Enter the code. Hint: *Yumi Zouma*.');
} else {
return;
}
How can I make the bot handle DM from other users? Google seems to only provide how to send a DM to a user.
What you need to use then is a Message Collector.
Docs
For example,
const dm = await reactUser.send("Enter code")
const collector = dm.channel.createMessageCollector({filter, max: 5, time: 30000}); //We're creating the collector, allowing for a max of 5 messages or 30 seconds runtime.
collector.on('collect', m => {
console.log(m.content)
}
collector.on('end', (collected, reason) => {
await dm.channel.send({content: `Collector ended for reason: ${reason} reached! I collected ${collected.size} messages.`})
}

How can send DM for unban command used user?

I'm developing an unban command for a ban command.
When the ban is lifted, I want the embed message unbanEmbeduserside to be sent to the banned user via private message. This embed message will let the banned user know about it.
The codes for my unban command are as follows. Thanks in advance to my friends who will help me with how to write a code so that I can perform the operation I mentioned in the above article.
async run (bot, message, args) {
message.delete(message.author);
if (!message.member.hasPermission("BAN_MEMBERS"))
return message.author.send("Buna yetkin yok.")
let unbanEmbednotfoundmessage = new discord.MessageEmbed()
.setColor(0xdb2727)
.setDescription(`Kullanıcı bulunamadı veya yasaklı değil.`);
let userID = args[0]
message.guild.fetchBans().then(bans => {
if(bans.size == 0) return message.channel.send(unbanEmbednotfoundmessage);
let bUser = bans.find(b => b.user.id == userID)
if(!bUser) return message.channel.send(unbanEmbednotfoundmessage)
let unbanEmbeduserside = new discord.MessageEmbed()
.setAuthor('YASAKLAMA KALDIRILDI', 'https://i.hizliresim.com/midfo22.jpg')
.setDescription(`
*Yasaklamanız kaldırıldı, sunucuya tekrar katılabilirsiniz!*
Yasaklamayı Kaldıran Yetkili: **${message.author.username}**
`)
.setColor(0xc8b280)
.setTimestamp()
.setFooter('gtaplus Multiplayer Community');
let unbanEmbedserverside = new discord.MessageEmbed()
.setAuthor('YASAKLAMA KALDIRMA', 'https://i.hizliresim.com/midfo22.jpg')
.setDescription(`
Yasağı Kaldırılan Kullanıcı: **${userID}**
Yasaklamayı Kaldıran Yetkili: **${message.author.username}**
`)
.setColor(0xc8b280)
.setTimestamp()
.setFooter('gtaplus Multiplayer Community');
message.guild.members.unban(bUser.user).then(() => message.channel.send(`**${userID}** yasaklaması kaldırıldı.`));
if (unbanEmbedserverside){
const log = message.guild.channels.cache.find(channel => channel.name === 'server-log')
log.send(unbanEmbedserverside);
}
})
}}
In Discord, any user, including a bot, will need to be in a server with a user to send them direct messages. This, unfortunately, means that unless the bot shares a server with the banned user, you will not be able to send the message. If the bot does share another server, the answer that Skularun Mrusal provided in the comments of your post should work.

Bot comes online but the embed won't post on discord

i'm new to programming and started making a discord bot by watching a few tutorials. I want the bot to DM the discord embed to the user who types "-buy" in a text channel. When running the code, the bot comes online and runs the "your bot name is online!" but no DM is sent. I would greatly appreciate any help. Thanks
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '-';
client.once('ready', () => {
console.log('your bot name is online!');
});
client.on('message', message =>{
if(message.author.client) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLocaleLowerCase();
if(command === 'buy'){
const testEmbed = new Discord.MessageEmbed()
.setColor(0x7f03fc)
.setTitle('test embeddy')
.setDescription('test description woo')
.setFooter('this is the footer')
try {
message.author.send(testEmbed);
} catch {
message.reply('Sorry I cannot message you! Check if your DMs are public!')
}
}
});
client.login('');
the token isn't the problem, i deleted it so i could upload here
The message.author.client returns the bot client, and it doesn't return a boolean. So your bot is blocked from there. Try removing that code and write message.author.bot that returns a boolean if the message author is a bot user. It will work.

How i can make a discord bot in specific channel delete and resends msg

How i can make a discord bot in specific channel and who ever write delete that message and resend it ?
Assuming you want the bot to resend any message as the bot in a specific channel here's an example using Discord.js
If I misunderstood and you want the bot to send a message as a specific user, that's not possible.
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('message', msg => {
if (msg.channel.name === 'channel name') {
msg.delete();
msg.channel.send(msg.content);
}
});
client.login('token');

Send is not a function discord.js

I am trying to send a message to channel but I keep getting Error: send is not a function.I have been stuck on this problem for over an hour.
What I have tried:
using sendMessage
tried reading the discord.js documentation but it doesnt seem to be working at all.
Here is my code:
//Grab the Discord Library
const Discord = require("discord.js");
//What will connect to the server.
const bot = new Discord.Client();
//
bot.on('ready', () => {
console.log("Connected as " + bot.user.tag)
//Shows and set the activity of the user.
bot.user.setActivity("El Professor build me", {type: "Watching"})
//Inform you of the servers this bot is connected to.
bot.guilds.forEach((guild) => {
console.log(guild.name)
guild.channels.forEach((channel) => {
console.log(` - ${channel.name} ${channel.type} ${channel.id}`)
})
//Voice Channel ID =
})
var generalChannel = bot.channels.get("123456789").send("Hello World")
})
Error message:
C:\Users\F4_ALFA\documents\FirstDiscordBot\index.js:21
var generalChannel = bot.channels.get("123456789").send("Hello World")
^
TypeError: bot.channels.get(...).send is not a function
at Client.bot.on (C:\Users\F4_ALFA\documents\FirstDiscordBot\index.js:21:63)
at Client.emit (events.js:194:15)
at WebSocketConnection.triggerReady (C:\Users\F4_ALFA\documents\FirstDiscordBot\node_modules\discord.js\src\client\websocket\WebSocketConn
ection.js:125:17)
at WebSocketConnection.checkIfReady (C:\Users\F4_ALFA\documents\FirstDiscordBot\node_modules\discord.js\src\client\websocket\WebSocketConn
ection.js:141:61)
at GuildCreateHandler.handle (C:\Users\F4_ALFA\documents\FirstDiscordBot\node_modules\discord.js\src\client\websocket\packets\handlers\Gui
ldCreate.js:13:31)
at WebSocketPacketManager.handle (C:\Users\F4_ALFA\documents\FirstDiscordBot\node_modules\discord.js\src\client\websocket\packets\WebSocke
tPacketManager.js:103:65)
at WebSocketConnection.onPacket (C:\Users\F4_ALFA\documents\FirstDiscordBot\node_modules\discord.js\src\client\websocket\WebSocketConnecti
on.js:333:35)
at WebSocketConnection.onMessage (C:\Users\F4_ALFA\documents\FirstDiscordBot\node_modules\discord.js\src\client\websocket\WebSocketConnect
ion.js:296:17)
at WebSocket.onMessage (C:\Users\F4_ALFA\documents\FirstDiscordBot\node_modules\ws\lib\event-target.js:120:16)
at WebSocket.emit (events.js:189:13)
Discord.js uses cache and your code has no '.cache', you should try
bot.channels.cache.get('id').send('Hello world!')
The channels property returns a Collection with pair of ID and Channel object.
The Channel class could represent any channel in discord. You couldn't send any messages through it because it doesn't have send() method.
I’ve used this before client.guilds.find(x => x.name === "ChatLogs").channels.find(y => y.name === "server-testing1").send(botEmbed) try that

Resources