[英]Discord.js doesn't do anything
My code worked fine but I changed some things and now it doesn't...我的代码运行良好,但我改变了一些东西,现在它没有......
When I type !ping
in the any channel it doesn't work.当我在任何频道中输入
!ping
时,它不起作用。
const Discord = require(`discord.js`),
client = new Discord.Client(),
prefix = `!`,
NO = `801418578069815297`
YES = `801418578300764180`
client.login(`bruh`)
client.once(`ready`, () => {
console.log(`online.`)
client.user.setPresence({
status: `online`,
game: {
name: `You`,
type: `WATCHING`
}
})
})
client.on(`message`, message =>{
if(!message.content.startsWith(prefix) || message.author.client) return
const args = message.content.slice(prefix.length).trim().split(` `)
const arg = args.toString().split(sep)
const command = args.shift().toLowerCase()
if(command === `ping`){
message.channel.send(`pong!`)
}
}
)
EDIT:编辑:
I put some log outputs in:我把一些日志输出放在:
const Discord = require("discord.js");
let client = new Discord.Client();
let prefix = "!";
console.log("discord, client, prefix defined.")
client.login("bruh");
console.log("logged in.")
client.once("ready", () => {
console.log("online.");
client.user.setPresence({
status: "online",
game: {
name: "You",
type: "WATCHING"
}
});
});
client.on("message", message =>{
console.log("message recieved")
if(!message.content.startsWith(prefix) || message.author.client) return;
console.log("it's a command.")
const args = message.content.slice(prefix.length).trim().split(" ");
console.log("splitted.")
const arg = args.toString().split(sep);
console.log("args defined.")
const command = args.shift().toLowerCase();
console.log("command defined.")
if(command === "ping") {
console.log("command identified:"+command)
message.channel.send("pong!");
console.log("message sent.")
}
});
The output is: output 是:
logged in.
online.
message recieved
I looked at that closely but still didn't find anything...我仔细看了看,但还是没有发现任何东西……
The problem is, you're using commas where you should be using semicolons, so JS will be interepreting this strangely which will give you undefined behaviour.问题是,你在应该使用分号的地方使用逗号,所以 JS 会奇怪地解释这一点,这会给你带来未定义的行为。 You should also preferably prefix your variables with
let
, var
or const
otherwise this could also lead to undefined behaviour.您还应该最好在变量前加上
let
、 var
或const
,否则这也可能导致未定义的行为。 It is recommended to use let
over var
.建议使用
let
over var
。
Try the code below to fix your problem:试试下面的代码来解决你的问题:
const Discord = require(`discord.js`);
let client = new Discord.Client();
let prefix = '!';
let NO = "801418578069815297";
let YES = "801418578300764180";
client.login(`bruh`);
client.once(`ready`, () => {
console.log(`online.`);
client.user.setPresence({
status: `online`,
game: {
name: `You`,
type: `WATCHING`
}
});
});
client.on(`message`, message =>{
if(!message.content.startsWith(prefix) || message.author.client) return;
const args = message.content.slice(prefix.length).trim().split(' ');
const command = args.shift().toLowerCase();
if(command === `ping`) {
message.channel.send(`pong!`);
}
});
I've had problems in the past with using wrong quotation marks, that might be the case for you here as well过去我在使用错误的引号时遇到过问题,您在这里也可能是这种情况
Try to replace all your ` with ' or "尝试用 ' 或 " 替换所有的 `
I found a way to make it work.我找到了让它工作的方法。 contact me on discord Moderpo#0172 if you wanna know the answer I'll have to find out what I did because I forgot lol
如果您想知道答案,请通过 discord Moderpo#0172 与我联系,我将不得不找出我做了什么,因为我忘记了哈哈
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.