Parasing Error: Unexpected Token, I think I added an extra } - discord.js

Im having problems with my code it says Parsing Error Unexpected Token Please Help, discord.js code ;-;
Im making an eval command btw so if you help it'd really be appreciated ( it says most of the post is code so Im adding some text pls ignore this - haha guns go brrrrrrrrrr)
const { Message } = require('discord.js');
const Client = require('../../classes/Unicron');
const BaseCommand = require('../../classes/BaseCommand');
const Util = require('util');
const fetch = require('node-fetch')
module.exports = class extends BaseCommand {
constructor() {
super({
config: {
name: 'eval',
description: 'Only The Owner Can Use This Command!',
permission: 'Bot Owner',
},
options: {
aliases: [],
clientPermissions: [],
cooldown: 3,
nsfwCommand: false,
args: true,
usage: 'eval [js input]',
donatorOnly: false,
premiumServer: false,
}
});
}
/**
* Return the exchange rate for one crypto currency in terms of other currencies.
* #param {string} fsym
* #param {Array<string>} tsyms
* #param {Message} message
*/
async run (client, message, args) {
if (message.author.id !== 'ownerID') return; {
let evaled;
try {
evaled = await eval(args.join(' '));
message.channel.send(inspect(evaled));
console.log(inspect(evaled));
}
catch (error) {
console.error(error);
message.reply('there was an error during evaluation.');
}
}
}

You're missing an extra } at the end. Also, that if (message.author.id !== 'ownerID') return; makes no sense in context.

Related

how to fix cannot read properties of undefined (reading 'push') in mongodb with djs

const { Client, CommandInteraction, EmbedBuilder, Permissions, ApplicationCommandType } = require("discord.js");
const { Formatters } = require('discord.js');
const blacklistedWords = require("../../Collection/index.js");
const Schema = require('../../models/blacklist.js')
module.exports = {
name: "blacklist_add",
description: "add a word to blacklist so that the members of the server cannot use the word",
userPerms: ['Administrator'],
type: ApplicationCommandType.ChatInput,
options: [{
name: 'word',
description: 'word to be added to the blacklist',
type: 3,
required: true
}],
/**
*
* #param {Client} client
* #param {CommandInteraction} interaction
* #param {String[]} args
*/
run: async (client, interaction, args) => {
const sword = interaction.options.getString('word');
console.log(sword)
const word = sword.toLowerCase();
const guild = { Guild: interaction.guild.id }
Schema.findOne(guild, async(err, data) => {
if(data) {
if(data.Words.includes(word)) return interaction.followUp(`The word already exists in the blacklist did you mean to remove it if so please use /blacklist-remove ${word} to remove the word from blacklist`)
data.Words.push(word)
data.save();
blacklistedWords.get(interaction.guild.id).push(word);
}else {
new Schema({
Guild: interaction.guild.id,
Words: word
}).save();
blacklistedWords.set(interaction.guild.id, [ word ])
}
const embed = new EmbedBuilder()
.setTitle('<:donetick:951395881607893062> Blacklist system')
.setColor('GREEN')
.setDescription('Word added- A new word has been added to the blacklist')
.addField('Word', `${word}`, false)
.addField('How do I remove the word from the blacklist?', `/blacklist-remove ${word}`, false)
interaction.reply({ embeds: [embed] })
});
},
};
this is the code but it used to work with djs v13 idk now why is it giving this error
the error image in console
can you please help I am new to djs v14 so I think that is an error caused by upgrading to v14 correct me if wrong

ElasticSearch | Delete function not working since update 8.0

In our React project, we use the npm package "#elastic/elasticsearch".
Since 8.0 migration, delete function is not working. We implement it this way:
// 1) Declaration of client instance
import { Client } from '#elastic/elasticsearch';
import Config from 'src/config';
const client = new Client(Config.get('/authentication/elastic'));
export default client;
// 2) Use delete fonction
public async delete(id: string): Promise<any> {
try {
return await this.client.delete({
index: this.indexName,
id: id,
});
} catch (e) {
return null;
}
}
The promise does not return an error, it sends this:
{
_index: 'visitor_0',
_id: 'RN-PdzFW-Yfr0ahMp',
_version: 3,
result: 'deleted',
_shards: { total: 2, successful: 1, failed: 0 },
_seq_no: 396,
_primary_term: 22
}
Problem, it does not delete the object. It updates it with empty content.
I try do delete manually on elastic dashboard, it works correctly.
I try do a small script by entering the id by hand, it also works.
// my small script
'use strict';
require('dotenv').config();
const util = require('util');
const elastic = require('./services/elastic/client').default;
const debug = o => console.log(util.inspect(o, false, null, true));
(async () => {
debug('Starting...');
const id = 'ChmG-wAL-YpjZAdGp';
try {
const result = await elastic.delete({ index: 'visitor', id });
debug(result);
} catch (e) {
debug(e);
}
})();
Do any of you have any idea where my problem could come from?

Problem: TypeError: Cannot read properties of null (reading 'roles')

I'm currently working on a kick command (following reconlx's Kick, Ban, and Unban command tutorial). All commands stop working (including the kick command).
If anyone can take a look, it'd be helpful.
Code for kick.js and the error is down below.
const { MessageEmbed, Message } = require("discord.js");
module.exports = {
name: 'kick',
description: 'Kicks a member',
userPermissions: ["KICK_MEMBERS"],
options: [
{
name: "member",
description: "The member you wish to kick",
type: "USER",
required: true
},
{
name: "reason",
description: "Reason for kicking",
type: "STRING",
required: false
},
],
/**
* #param {Client} client
* #param {CommandInteraction} interaction
* #param {String[]} args
*/
run: async (client, interaction, args) => {
const target = interaction.options.getMember("target");
const reason =
interaction.options.getString("reason") || "No reason(s) provided";
const rolePositionCheck = new MessageEmbed()
.setTitle("You can't kick a person with a higher role than yours!")
.setFooter({ text: "Error: Lower Role Position"})
if (
target.roles.highest.position >=
interaction.member.roles.highest.position
)
return interaction.followUp({
embeds:
[rolePositionCheck],
});
// Message which is sent to the person kicked
const kickMessage = new MessageEmbed()
.setTitle(`You've been kicked from ${interaction.guild.name}`)
.setFooter({ text: `Reason: ${reason}` })
await target.send({ embeds: [kickMessage] });
// The action of kicking, along with the reason
target.kick(reason)
// Message which is sent to the mod who kicked.
const kickAftermath = new MessageEmbed()
.setTitle(`${target.user.tag} has been kicked!`)
.setFooter({ text: `${reason}` })
interaction.followUp({
embeds:
[kickAftermath],
});
},
};
Error
TypeError: Cannot read properties of null (reading 'roles')
at Object.run (C:\Users\admin\Desktop\Tonkotsu\SlashCommands\moderation\kick.js:38:20)
at Client.<anonymous> (C:\Users\admin\Desktop\Tonkotsu\events\interactionCreate.js:27:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

How do I use #discordjs/voice AudioPlayer methods across modules?

I am adding a music-playing feature to my bot using #discordjs/voice, following the voice guide on discordjs.guide. My slash commands are all stored on different files. I want to use the pause method of the AudioPlayer class outside of play.js.
The relevant parts of play.js are:
const { SlashCommandBuilder } = require('#discordjs/builders');
const { StreamType, createAudioPlayer, createAudioResource, joinVoiceChannel } = require('#discordjs/voice');
module.exports = {
data: new SlashCommandBuilder()
.setName('play')
.setDescription('An example of the play command.'),
async execute(interaction) {
const connection = joinVoiceChannel({ channelId: interaction.member.voice.channel.id, guildId: interaction.guild.id, adapterCreator: interaction.guild.voiceAdapterCreator });
const stream = ytdl('https://www.youtube.com/watch?v=jNQXAC9IVRw', { filter: 'audioonly' });
const resource = createAudioResource(stream, { inputType: StreamType.Arbitrary });
const player = createAudioPlayer();
player.play(resource);
connection.subscribe(player);
await interaction.reply('Playing.');
},
};
and of pause.js are:
const { SlashCommandBuilder } = require('#discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('pause')
.setDescription('An example of the pause command.'),
async execute(interaction) {
player.pause();
await interaction.reply('Paused.');
},
};
My console got the following error when I ran the /pause command after I tried to export player from player.js and require it in pause.js:
TypeError: Cannot read properties of undefined (reading 'pause')
What do I need to do to use player.pause() outside of play.js?
You should take a look at this part of the Discord.js guide, in the Access part. The getVoiceConnection method serves this purpose.
It allows you to use the connection created in play.js anywhere in your code. Then, you just need to change the state of the player with connection.state.subscription.player.pause().
I did my pause.js by checking whether the member using the pause command is in a channel and if he is, whether the bot is in it or not:
if (!interaction.member.voice.channelId) {
return interaction.reply('not in a channel.');
}
const connection = getVoiceConnection(interaction.member.voice.channel.guildId);
if (!connection || (connection.joinConfig.channelId != interaction.member.voice.channelId)) {
return interaction.reply('The bot is not in this channel.');
}
connection.state.subscription.player.pause();
await interaction.reply('Paused.');
discord.js

discord.js-commando TypeError: RichEmbed is not a constructor

I want to send embed with discord.js-commando but when I send the command it says me this:
An error occurred while running the command: TypeError: RichEmbed is not a constructor
You shouldn't ever receive an error like this.
here is my code
const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js');
module.exports = class EmbedCommand extends Command {
constructor(client) {
super(client, {
name: 'embed',
group: 'util',
memberName: 'embed',
description: 'Embeds the text you provide.',
examples: ['embed Embeds are cool.'],
args: [
{
key: 'text',
prompt: 'What text would you like the bot to embed?',
type: 'string'
}
]
});
}
run(msg, args) {
const { text } = args;
const embed = new RichEmbed()
.setDescription(text)
.setAuthor(msg.author.username, msg.author.displayAvatarURL)
.setColor(0x00AE86)
.setTimestamp();
return msg.embed(embed);
}
};
If you’re using discord.js v12+ it’s Discord.MessageEmbed()
RichEmbed is called MessageEmbed in newest Versions. Renaming it should be fine.

Resources