How would i fix the message.guild.channels.create i keep getting a error when its sopost to make a channel can anyone help me with this i tried what i could to fix this as well
async execute(message, args, cmd, client, discord) {
const channel = await message.guild.channels.create(`Ticket: ${user.author}`, {
type: 'text',
permissionOverwrites: [
{
id: message.guild.id,
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
},
{
id: message.author.id,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
},
],
}).then(res => channel.setParent("855596395783127081"));
}
PS C:\Users\lolzy\OneDrive\Desktop\discordbot> node . Cbs slave is
online! (node:25580) UnhandledPromiseRejectionWarning: TypeError:
Cannot read property 'channels' of undefined
at Object.execute (C:\Users\lolzy\OneDrive\Desktop\discordbot\commands\ticket.js:7:45)
at module.exports (C:\Users\lolzy\OneDrive\Desktop\discordbot\events\guild\message.js:10:26)
at Client.emit (events.js:376:20)
at MessageCreateAction.handle (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:376:20) (Use node --trace-warnings ... to show where the warning was created) (node:25580)
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:25580) [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.
Message.guild is optional for a Message. In other words, it can be undefined if the message was not sent from a guild channel, as the log suggests. Your code should check that it is not undefined before trying to access Guild properties and methods.
async execute(message, args, cmd, client, discord) {
const guild = message.guild;
if (guild !== undefined) {
let guildChannel = await guild.channels.create(`Ticket: ${user.author}`, {
type: 'text',
parent: '855596395783127081',
permissionOverwrites: [
{
id: message.guild.id,
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
},
{
id: message.author.id,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
},
],
});
}
}
Related
I'm making a unban command, it was all going well till I tried to make a unban command, I can't use .catch to check if the user is banned or not, so is there a better way or a fix?
I'm planning on changing it to embeds to add more style to it, if that may help you some how :D
Here is the ban / unban command:
const { MessageEmbed } = require('discord.js');
//ban
module.exports = {
name: 'ban',
category: 'Owner',
description: 'Bans a member.',
aliases: [],
usage: 'ban <user>',
userperms: [],
botperms: [],
run: async (client, message, args) => {
if (!message.guild.member(message.author).hasPermission("BAN_MEMBERS")) {
return message.channel.send('You do not have the permission to ban users!');
}
if (!message.guild.member(client.user).hasPermission("BAN_MEMBERS")) {
return message.channel.send("I don't have the permission to ban users!");
}
if (message.mentions.users.size === 0) {
return message.channel.send("Can't find this member.");
}
if (message.mentions.members.first().id == message.author.id) {
return message.channel.send("Silly you, why are you trying to ban yourself?")
}
var member = message.mention.members.first();
member
.ban()
.then(member => {
guild.members.ban(id);
message.channel.send("*it's not a bird,*, *it's just* **" + member.displayName + "** *getting banned! :hammer:*");
})
.catch(() => {
message.channel.send("You can't ban this member");
});
},
};
//unban
module.exports = {
name: 'unban',
category: 'Owner',
description: 'Unbans a banned member.',
aliases: [],
usage: 'unban <user>',
userperms: [],
botperms: [],
run: async (client, message, args) => {
if (!message.guild.member(message.author).hasPermission("BAN_MEMBERS")) {
return message.channel.send('You do not have the permission to unban users!');
}
if (!message.guild.member(client.user).hasPermission("BAN_MEMBERS")) {
return message.channel.send("I don't have the permission to unban users!");
}
if (message.mentions.users.size === 0) {
return message.channel.send("Can't find this member.");
}
if (message.mentions.members.first().id == message.author.id) {
return message.channel.send("Lol, your not banned....")
}
var member = message.mentions.members.first();
(member => {
message.guild.members.unban(id)
message.channel.send("**" + member.displayName + "** **unbanned! :hammer:**");
})
.catch(() => {
message.channel.send("User not banned.");
});
},
};
Error:
(node:1551) UnhandledPromiseRejectionWarning: TypeError: message.mentions.members.first.catch is not a function
at Object.run (/home/runner/DwaCraft-Ticket-bot/commands/owner/ban-unban.js:65:45)
at module.exports (/home/runner/DwaCraft-Ticket-bot/events/guild/message.js:55:11)
at Client.emit (events.js:314:20)
at MessageCreateAction.handle (/home/runner/DwaCraft-Ticket-bot/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (/home/runner/DwaCraft-Ticket-bot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/runner/DwaCraft-Ticket-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/home/runner/DwaCraft-Ticket-bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/home/runner/DwaCraft-Ticket-bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/home/runner/DwaCraft-Ticket-bot/node_modules/ws/lib/event-target.js:132:16)
at WebSocket.emit (events.js:314:20)
(node:1551) 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:1551) [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.
You might need to chain the catch block with the unban function.
message.guild.members.unban(id)
.then(() => {
message.channel.send("**" + member.displayName + "** **unbanned! :hammer:**" )
})
.catch(() => {
message.channel.send("User not banned.");
})
You can get the member's Id from the member variable through member.id
i need help with this for someone reason when i type !ticket it gives me a error the code and the error i tried what i could i couldent get it to work so i came here to ask please let me know if you could help. its probably a really simple issue and im dumb to realize it. i also cant get the emojis to work if you can help with that as well that would be nice
const Discord = require("discord.js")
const ms = require('ms');
module.exports = {
name: 'ticket',
usage: '%ticket <reason>',
description: 'makes a ticket',
async execute(client, message, args, cmd, discord) {
const channel = await message.guild.channels.create(`ticket: ${message.user.tag}`);
channel.setParent('855596395783127081');
channel.updateOverwrite(message.guild.id, {
SEND_MESSAGE: false,
VEIW_CHANNEL: false
})
channel.updateOverwrite(message.auther, {
SEND_MESSAGE: true,
VEIW_CHANNEL: true
})
const reactionMessage = await channel.send(`Thank you for contacting support! A staff member will be with you as soon as possible`);
try {
await reactionMessage.react(":lock:");
await reactionMessage.react(":no_entry:");
} catch (err) {
channel.send(`Error Sending Emojis`);
throw err;
}
const collector = reactionMessage.createReactionCollector((reaction, user) =>
message.guild.member.cache.find((member) => member.id === userid).hasPermission('ADMINISTRATOR'), { dispose: true }
);
collector.on('collect', (reaction, user) => {
switch (reaction.emoji.name) {
case ":lock:":
channel.updateOverwrite(message.auther, { SEND_MESSAGE: false });
break;
case ":no_entry:":
channel.send('Deleteing ticket in 5 seconds');
setTimeout(() => channel.delete(), 5000);
break;
}
});
message.channel.send(`We will be right withyou! ${channel}`).then((msg) => {
setTimeout(() => msg.delete(), 7000)
setTimeout(() => message.delete(), 7000)
})
}
}
Heres the error
PS C:\Users\lolzy\OneDrive\Desktop\discordbot> node .
Cbs slave is online!
(node:19284) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'tag' of undefined
at Object.execute (C:\Users\lolzy\OneDrive\Desktop\discordbot\commands\ticket.js:10:85)
at module.exports (C:\Users\lolzy\OneDrive\Desktop\discordbot\events\guild\message.js:10:26)
at Client.emit (events.js:376:20)
at MessageCreateAction.handle (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:376:20)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:19284) 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:19284) [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.
In Message Object there is no properties that called .user it should be .author which is return User Object , docs here
So the right code will be
const channel = await message.guild.channels.create(`ticket: ${message.author.tag}`);
Dicord bot and sorry by my english is some bad:
client.on("ready", () => {
console.log(`Genesis bot online!`);
client.user.setPresence({
status: "online",
game: {
name: "Official Discord Bot",
type: "PLAYING" //PLAYING, LISTENING, WATCHING
}
});
setInterval(async function(){
let msg = await client.channels.cache.get(channelID).channel.messages.cache.get(messageID);
let stafflist = new MessageEmbed()
.setColor("GOLD")
.setTitle("Staff Members")
.setDescription(client.guilds.cache.get(serverID).roles.cache.find((r) => r.name == "➦「Staff Member」").members.map((m) => `\`${m.user.tag}\``).join(", "));
msg.edit(stafflist)
}, 3000);
});
this is the complete error:
(node:276) UnhandledPromiseRejectionWarning: TypeError: Cannot read
property 'get' of undefined
at Timeout._onTimeout (N:\Genesis bot\Genesisbot2.0\index.js:34:47)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7) (Use node --trace-warnings ... to show where the warning was created) (node:276) 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:276) [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.
I suspect there is something wrong with my code but I don't know.
const Discord = require('discord.js');
const client = new Discord.Client();
const config = require('./config.json');
client.once('ready', () => {
console.log('Bot online!');
});
client.on('message', async message => {
if(message.content.voice.channel) {
const connection = await message.member.voice.channel.join();
const dispatcher = connection.playFile(require("path").join(__dirname, './audio.mp3'));
dispatcher.on('start', () => {
console.log('Now playing!');
});
dispatcher.on('finish', () => {
console.log('Finished playing!');
voiceChannel.leave();
});
dispatcher.on('error', console.error);
}
});
client.login(config.TOKEN);
I get error :
UnhandledPromiseRejectionWarning: TypeError: Cannot read property
'channel' of undefined
at Client. (C:\Users\djd18\Desktop\Bot\index.js:10:30)
at Client.emit (events.js:315:20)
at MessageCreateAction.handle (C:\Users\djd18\Desktop\Bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\djd18\Desktop\Bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\djd18\Desktop\Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\djd18\Desktop\Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\djd18\Desktop\Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\djd18\Desktop\Bot\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:315:20)
at Receiver.receiverOnMessage (C:\Users\djd18\Desktop\Bot\node_modules\ws\lib\websocket.js:825:20)
(Use node --trace-warnings ... to show where the warning was
created) (node:16536) 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:16536) [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.
I'm using discord.js to try make a bot with the sole purpose of whenever a member is given a specific role (alpha, bravo, charlie, delta) it will send an announcement to a specific channel (#general) saying congratulations on becoming part of the faction! How would I go about doing this? (what I know is that it's part of the "GuildMembers" chunk)
const Discord = require('discord.js');
const client = new Discord.Client();
const token = 'NzUzNTY0NjA0MjM1MzgyODI1.X1oBug.E0GEmnakRtQMbOfg5IwllQsW_Ps';
client.on('ready', () => {
console.log('This bot is online!')
})
client.on("guildMemberUpdate", async(oldMember, newMember) => {
// On `guildMemberUpdate`
if (oldMember.roles.cache !== newMember.roles.cache) {
// Check if a role was updated
let newRole;
newMember.roles.cache.forEach((role) => {
if (oldMember.roles.cache.includes(role)) return;
// Check for the new role that was added
let roleNames = ["bobbies", "beebos", "babbos", "bobbios"];
if (roleNames.toLowerCase().includes(role.name.toLowerCase())) {
// Check for only `['bobbies', 'beebos', 'babbos', 'bobbios']`
newRole = role;
}
});
// Anything you want to run here with the `newRole` data.
const channel = oldMember.guild.channels.cache.find(
(channel) => channel.name === "general"
);
channel.send("Congratulations on becoming part of the faction!");
}
});
client.login(token);
This unfortunately returns with the error:
(node:6240) UnhandledPromiseRejectionWarning: TypeError: oldMember.roles.cache.includes is not a function
at C:\Users\sanderj\Desktop\Discord Bot\index.js:18:39
at Map.forEach (<anonymous>)
at Client.<anonymous> (C:\Users\sanderj\Desktop\Discord Bot\index.js:17:31)
at Client.emit (events.js:315:20)
at Object.module.exports [as GUILD_MEMBER_UPDATE] (C:\Users\sanderj\Desktop\Discord Bot\node_modules\discord.js\src\client\websocket\handlers\GUILD_MEMBER_UPDATE.js:25:16)
at WebSocketManager.handlePacket (C:\Users\sanderj\Desktop\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\sanderj\Desktop\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\sanderj\Desktop\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\sanderj\Desktop\Discord Bot\node_modules\ws\lib\event-target.js:125:16)
at WebSocket.emit (events.js:315:20)
(node:6240) 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:6240) [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.
Check out Client#guildMemberUpdate which gets emitted when something about a member property gets changed (i.e. a role is added). Try adding this code to your bot:
client.on("guildMemberUpdate", async (oldMember, newMember) => {
// On `guildMemberUpdate`
if (!oldMember.roles.cache.equals(newMember.roles.cache)) {
// Check if a role was updated
let newRole;
newMember.roles.cache.forEach((role) => {
if (oldMember.roles.cache.includes(role)) return;
// Check for the new role that was added
let roleNames = ["alpha", "bravo", "charlie", "delta"];
if (roleNames.toLowerCase().includes(role.name.toLowerCase())) {
// Check for only `['alpha', 'bravo', 'charlie', 'delta']`
newRole = role;
}
});
// Anything you want to run here with the `newRole` data.
const channel = oldMember.guild.channels.cache.find(
(channel) => channel.name === "general"
);
channel.send("Congratulations on becoming part of the faction!");
}
});