Discord bot başlatırken "Cannot find module" hatası

370728

Hectopat
Katılım
26 Eylül 2020
Mesajlar
1.447
Çözümler
4
Kod:
Error: Cannot find module '/ayarlar.json'
Require stack:
- C:\Users\admin\Desktop\Bot-discord\bot.js
←[90m at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:769:27)←[39m
←[90m at Module.require (node:internal/modules/cjs/loader:997:19)←[39m
←[90m at require (node:internal/modules/cjs/helpers:92:18)←[39m
at Object.<anonymous> (C:\Users\admin\Desktop\Bot-discord\bot.js:3:17)
←[90m at Module._compile (node:internal/modules/cjs/loader:1108:14)←[39m
←[90m at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)←[39m
←[90m at Module.load (node:internal/modules/cjs/loader:973:32)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:813:14)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)←[39m {
code: ←[32m'MODULE_NOT_FOUND'←[39m,
requireStack: [ ←[32m'C:\\Users\\admin\\Desktop\\Bot-discord\\bot.js'←[39m ]

Arkadaşlar bu hatayı alıyorum. Sebebi nedir? Kodları atmama gerek var mı?
 
Kod:
Error: Cannot find module '/ayarlar.json'
Require stack:
- C:\Users\admin\Desktop\Bot-discord\bot.js
←[90m at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:769:27)←[39m
←[90m at Module.require (node:internal/modules/cjs/loader:997:19)←[39m
←[90m at require (node:internal/modules/cjs/helpers:92:18)←[39m
at Object.<anonymous> (C:\Users\admin\Desktop\Bot-discord\bot.js:3:17)
←[90m at Module._compile (node:internal/modules/cjs/loader:1108:14)←[39m
←[90m at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)←[39m
←[90m at Module.load (node:internal/modules/cjs/loader:973:32)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:813:14)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)←[39m {
code: ←[32m'MODULE_NOT_FOUND'←[39m,
requireStack: [ ←[32m'C:\\Users\\admin\\Desktop\\Bot-discord\\bot.js'←[39m ]

Arkadaşlar bu hatayı alıyorum. Sebebi nedir? Kodları atmama gerek var mı?
C:\Users\admin\Desktop\Bot-discord içinde ayarlar.json var mı?
Kopyala yapıştırsa olması doğal, kodları atarsanız çözebiliriz. Ve size geri atarım. Ama tokeni atmayın sakın!
 
Kod:
Error: Cannot find module '/ayarlar.json'
Require stack:
- C:\Users\admin\Desktop\Bot-discord\bot.js
←[90m at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:769:27)←[39m
←[90m at Module.require (node:internal/modules/cjs/loader:997:19)←[39m
←[90m at require (node:internal/modules/cjs/helpers:92:18)←[39m
at Object.<anonymous> (C:\Users\admin\Desktop\Bot-discord\bot.js:3:17)
←[90m at Module._compile (node:internal/modules/cjs/loader:1108:14)←[39m
←[90m at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)←[39m
←[90m at Module.load (node:internal/modules/cjs/loader:973:32)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:813:14)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)←[39m {
code: ←[32m'MODULE_NOT_FOUND'←[39m,
requireStack: [ ←[32m'C:\\Users\\admin\\Desktop\\Bot-discord\\bot.js'←[39m ]

Arkadaşlar bu hatayı alıyorum. Sebebi nedir? Kodları atmama gerek var mı?
Projenizin içinde ayarlar.json var mı?
 
C:\Users\admin\Desktop\Bot-discord içinde ayarlar.js var mı?
Kopyala yapıştırsa olması doğal, kodları atarsanız çözebiliriz. Ve size geri atarım. Ama tokeni atmayın sakın!

Evet var.

Screenshot_272.jpg


Kod:
const Discord = require('discord.js');
const client = new Discord.Client();
const ayarlar = require('/ayarlar.json');

var prefix = ayarlar.json;

client.on('ready', () => {
console.log(`Bot ${client.user.tag} aktif durumda !`);
});

client.on('message', msg => {
if (msg.content === 'selam') {
msg.reply('merhaba');
}
});

client.on('message', msg => {
if (msg.content === 'merhaba') {
msg.reply('selam')
}
});

client.login(':)');

Kod:
{
"prefix": ".",
"token": ":)",
"sahip": "373150024890056706"
}

Alttaki ayarlar.json.
 
Ayarları silin, ve şu şekilde düzenleyin bence:
JavaScript:
const Discord = require('discord.js');
const client = new Discord.Client();


const prefix = '.';
const sahip = '373150024890056706';

client.on('ready', () => {
console.log(`Bot ${client.user.tag} aktif durumda !`);
});

client.on('message', msg => {
if (msg.content === 'selam') {
msg.reply('merhaba');
}
});

client.on('message', msg => {
if (msg.content === 'merhaba') {
msg.reply('selam')
}
});

client.login('tokeninizi yazın');

Ben şöyle kullanıyorum:
Ya böyle, ya da üstteki gibi kullanın, @370728 .

JavaScript:
const { token } = require('./ayarlar.json');
client.login(token);
 
Hocam.
Const ayarlar = require('/ayarlar. Json');

Const ayarlar = require('./ayarlar. Json');

Olarak değiştirir misiniz?

Bunu yapınca da şimdi token hatası veriyor.
Ayarları silin, ve şu şekilde düzenleyin bence:
JavaScript:
const Discord = require('discord.js');
const client = new Discord.Client();

const prefix = '.';
const sahip = '373150024890056706';

client.on('ready', () => {
console.log(`Bot ${client.user.tag} aktif durumda !`);
});

client.on('message', msg => {
if (msg.content === 'selam') {
msg.reply('merhaba');
}
});

client.on('message', msg => {
if (msg.content === 'merhaba') {
msg.reply('selam')
}
});

client.login('tokeninizi yazın');

Ben şöyle kullanıyorum:
Ya böyle, ya da üstteki gibi kullanın, @370728.

JavaScript:
const { token } = require('./ayarlar.json');
client.login(token);

Bunu deniyieceğim birazdan.
 

Technopat Haberler

Yeni konular

Geri
Yukarı