我的代码似乎没有错误,但是当我运行此代码时:
const { Client } = require('discord.js', 'async');
const bot = new Client();
const cfg = require('./config.json');
bot.on('ready', () => {
console.log(`Bot Ready on ${bot.guilds.size} servers`);
bot.user.setActivity('the member list', {type: 3})
});
bot.on('message', msg => {
if (msg.author.bot || !msg.content.startsWith(cfg.prefix)) return;
const args = msg.content.slice(cfg.prefix.length).split(' ')
const command = args.shift().toLowerCase();
});
bot.on(guildMemberAdd, member => {
console.log('User ' + member.user.username + 'has joined the server, adding role')
var role = member.guild.roles.find('name', 'New Member')
member.addRole(role)
console.log(`Args: ${args}\nCommand: ${command}`)
});
bot.login(cfg.token);
这是一个侦听器函数,用于在用户加入时添加角色,它会引发此错误:
C:\Users\Sparxo\Desktop\AutoRole\app.js:16
bot.on(guildMemberAdd, member => {
^
ReferenceError: guildMemberAdd is not defined
at Object.<anonymous> (C:\Users\Moneq\Desktop\AutoRole\app.js:16:12)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
[nodemon] app crashed - waiting for file changes before starting...
在修改我的代码时,我没有看到明显的错误,所以我不知道该如何解决。有帮助吗?
答案 0 :(得分:1)
该错误向您显示guildMemberAdd未定义,这意味着guildMemberAdd在您的代码中不存在。您必须使用 string ,而不仅仅是使用侦听器名称本身,这是一个例如:
bot.on("guildMemberAdd", member => {
但是,如果它不起作用,则说明您使用的是discord.js
的过时版本
答案 1 :(得分:1)
from PIL import Image
from scipy.misc import imread
import numpy as np
img1 = imread('image1.png')
img1 = np.reshape(img1,(128,96))
y = list(np.reshape(img1,(1,12288)))
z = y[1:101]
print(z)
我现在正在我的机器人上执行此操作。如果这不起作用,则可以将“ client.on”更改为“ bot.on”。就像有些使用“ msg”,有些使用“ message”