I am very new to coding and I tried coding my own discord bot and I got the "discord is not refined" in command prompt. I am currently just trying to turn on the bot to see if it works, anyways here is the code
const Discord = require("discord.js");
const client = new Discord.Client();
client.once('ready'), () => {
console.log('HelloMyFriend is online!');
};
client.login('<token>');
stack trace
events.js:131
throw new ERR_INVALID_ARG_TYPE('listener', 'Function', listener);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received undefined
←[90m at checkListener (events.js:131:11)←[39m
←[90m at Client.once (events.js:496:3)←[39m
at Object.<anonymous> (C:\Users\jamie\Desktop\DiscordBot\main.js:7:8)
←[90m at Module._compile (internal/modules/cjs/loader.js:1068:30)←[39m
←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:933:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:774:14)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)←[39m
←[90m at internal/main/run_main_module.js:17:47←[39m {
code: ←[32m'ERR_INVALID_ARG_TYPE'←[39m
}
The first event on ready is wrong. You shouldn't be closing the parentheses after the 'ready'.
You should also use on instead of once.
client.on('ready', () => {
console.log('HelloMyFriend is online!');
});
To overcome this error you can replace your ready event with the following:
client.once('ready', () => {
console.log('HelloMyFriend is online!');
});
I would also recommend an .env file to protect the token of the bot. Once it becomes public, it should be generated again in the Discord Developer Portal to prevent possible hijacking of the bot.
Related
i have some Problems with my Code that somehow none of my friends have ...
Some Code to see:
module.exports = {
data: new SlashCommandBuilder()
.setName('equipment')
.setDescription('Gives you Information about specific Equipments')
.addStringOption(option =>
option.setName('type')
.setDescription('Specify the Equipment')
.setRequired(true)
.addChoice('Flashlight', 'flashlight')
),
...
The Code is Cut here because its not necesery for it above to work.
My Error Code:
PS C:\Users\enric\Desktop\Ghosty Phasmo Help> node .
C:\Users\enric\Desktop\Ghosty Phasmo Help\commands\phasmo\equipment.js:15
.addChoice('Flashlight', 'flashlight')
^
TypeError: option.setName(...).setDescription(...).setRequired(...).addChoice is not a function
at C:\Users\enric\Desktop\Ghosty Phasmo Help\commands\phasmo\equipment.js:15:18
at MixedClass._sharedAddOptionMethod (C:\Users\enric\Desktop\Ghosty Phasmo Help\node_modules\#discordjs\builders\dist\index.js:1334:50)
at MixedClass.addStringOption (C:\Users\enric\Desktop\Ghosty Phasmo Help\node_modules\#discordjs\builders\dist\index.js:1323:17)
at Object.<anonymous> (C:\Users\enric\Desktop\Ghosty Phasmo Help\commands\phasmo\equipment.js:11:7)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
Somehow my Discord.js thinks that im using a Function. I copied the Code from other friends where this completely work. but somehow the same Error message appears.
.addChoice() is outdated. Now, there is only .addChoices() (with an s)
.addStringOption(option =>
option.setName('type')
.setDescription('Specify the Equipment')
.setRequired(true)
.addChoices({
name: 'Flashlight',
value: 'flashlight'
})
)
I tried making a discord bot and I did the first steps and the command prompt when I type node . shows this:
TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client.
at Client._validateOptions (C:\Users\giann\Desktop\BWKS\node_modules\discord.js\src\client\Client.js:548:13)
at new Client (C:\Users\giann\Desktop\BWKS\node_modules\discord.js\src\client\Client.js:76:10)
at Object. (C:\Users\giann\Desktop\BWKS\main.js:2:16)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
[Symbol(code)]: 'CLIENT_MISSING_INTENTS'
}
I tried almomst everything but this error is coming up all the time.
the code:
const client = new Discord.Client();
client.once('ready', () => {
console.log('Ready')
});
client.login('the token');
Discord needs to know what intents you want to use. So to fix your code, use:
const client = new Discord.Client({ intents: [<ARRAY WITH ALL INTENTS>] });
client.once('ready', () => {
console.log('Ready')
});
client.login('the token');
You can add intents in the array by using a string "GUILDS" or use the property Intents.FLAGS.GUILDS
A list of all intents can be found here: https://discord.js.org/#/docs/discord.js/stable/class/Intents
I've tried multiple fixes and I am unable to figure out what is wrong send help...
The bot at the moment is supposed to run simple commands and hopefully sometime in the near future be an application bot
Index.js
const { Client, Collection } = require("discord.js");
const client = new Client({
intents: 32767,
});
module.exports = client;
// Global Variables
client.commands = new Collection();
client.slashCommands = new Collection();
client.config = require("./config.json");
// Initializing the project
require("./handler")(client);
client.login(client.config.token);
config.json
{
"token": "My discord bot token",
"prefix": "!",
}
error
C:\Users\Hello\djs-base-handler\index.js:16
client.login(token);
^
ReferenceError: token is not defined
at Object.<anonymous> (C:\Users\Hello\djs-base-handler\index.js:16:14)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
This is not how you get your token from your json, try this instead :
//assuming the file is on the root of your project, else put the full path
const { token } = require('./config.json')
//...
client.login(token)
I am trying to make a discord bot but when I did some code and ran it this error pops up:
index.js
const discord = require('discord.js')
const { token } = require('./config.json')
const Client = new discord.Client({
intents: [discord.Intents.FLAGS.GUILDS, discord.Intents.FLAGS.GUILD_MEMBERS, discord.Intents.FLAGS.GUILD_BANS, discord.Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS, discord.Intents.FLAGS.GUILD_INTEGRATIONS, discord.Intents.FLAGS.GUILD_WEBHOOKS, discord.Intents.FLAGS.GUILD_INVITES, discord.Intents.FLAGS.GUILD_VOICE_STATES, discord.Intents.FLAGS.GUILD_PRESENCES, discord.Intents.FLAGS.GUILD_MESSAGES, discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS, discord.Intents.FLAGS.GUILD_MESSAGE_TYPING, discord.Intents.FLAGS.DIRECT_MESSAGES, discord.Intents.FLAGS.DIRECT_MESSAGE_REACTION, discord.Intents.FLAGS.DIRECT_MESSAGE_TYPING]
})
Client.on('ready', () => {
console.log(`${Client.user.tag} is online!`)
})
Client.login(token)
config.json
{
"token": "my_token"
}
When I run the code I get this error
C:\Users\krisz\OneDrive\Desktop\TalkBot 2.9.56 Beta\node_modules\discord.js\src\util\BitField.js:152
throw new RangeError('BITFIELD_INVALID', bit);
^
RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number: undefined.
at Function.resolve (C:\Users\krisz\OneDrive\Desktop\TalkBot 2.9.56 Beta\node_modules\discord.js\src\util\BitField.js:152:11)
at C:\Users\krisz\OneDrive\Desktop\TalkBot 2.9.56 Beta\node_modules\discord.js\src\util\BitField.js:147:54
at Array.map (<anonymous>)
at Function.resolve (C:\Users\krisz\OneDrive\Desktop\TalkBot 2.9.56 Beta\node_modules\discord.js\src\util\BitField.js:147:40)
at Client._validateOptions (C:\Users\krisz\OneDrive\Desktop\TalkBot 2.9.56 Beta\node_modules\discord.js\src\client\Client.js:546:33)
at new Client (C:\Users\krisz\OneDrive\Desktop\TalkBot 2.9.56 Beta\node_modules\discord.js\src\client\Client.js:73:10)
at Object.<anonymous> (C:\Users\krisz\OneDrive\Desktop\TalkBot 2.9.56 Beta\index.js:3:16)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32) {
[Symbol(code)]: 'BITFIELD_INVALID'
}
How can I fix this issue?
I am using Discord.js V13
Node.js 16.7
Small Typo: DIRECT_MESSAGE_REACTION -> DIRECT_MESSAGE_REACTIONS on line 4 of index.js.
That's probably why node is freaking out about an invalid bitfield flag; discord.Intents.FLAGS.DIRECT_MESSAGE_REACTION is undefined (a.k.a it doesn't exist).
I'm very new to this. I dabbled in javascript about 10-15 years ago, but it was just editing existing files. I've been searching but I can't find a definitive guide for how to do this. I'm trying to make a command, and have the bot count up with it. Here's almost all of my code.
const Discord = require('discord.js');
const client = new Discord.Client();
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message => {
if (message.content === `!test`) {
async def cmd_thatcommand(self,channel):
await self.safe_send_message(channel, "+1")
counter += 1
return Response('command used {} times'.format(counter))
} else if (message.content === `!beep`) {
message.channel.send('Boop.');
} else if (message.content === `!server`) {
message.channel.send(`Server name: ${message.guild.name}\nTotal members: ${message.guild.memberCount}`);
} else if (message.content === `!user-info`) {
message.channel.send(`Your username: ${message.author.username}\nYour ID: ${message.author.id}`);
}
});
I've attempted a few lines I found online (such as bot counting command discord )but they always throw some kind of error. The one it gives for the above code is:
async def cmd_thatcommand(self,channel):
^^^
SyntaxError: Unexpected identifier
[90m at wrapSafe (internal/modules/cjs/loader.js:1054:16)[39m
[90m at Module._compile (internal/modules/cjs/loader.js:1102:27)[39m
[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)[39m
[90m at Module.load (internal/modules/cjs/loader.js:986:32)[39m
[90m at Function.Module._load (internal/modules/cjs/loader.js:879:14)[39m
[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)[39m
[90m at internal/main/run_main_module.js:17:47[39m
The guide I found for this uses Node and ESLint (if that helps at all).
def is not a thing in Java Script. Try using function instead if def. also instead if using ":" you have to use "{}" for example.
function example(){
console.log("This is how you make a function in Java Script");
}
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function