Javascript 已解决:使用ID管理特定用户

Javascript 已解决:使用ID管理特定用户,javascript,discord.js,Javascript,Discord.js,我通过其他问题试图找到答案,并得出以下代码: module.exports = { name: 'pray', description: 'Pray to the goddess!', usage: '[command name]', execute(message, args){ const Discord = require("discord.js"); const { Client } = require('discord.j

我通过其他问题试图找到答案,并得出以下代码:

module.exports = {
    name: 'pray',
    description: 'Pray to the goddess!',
    usage: '[command name]',
    execute(message, args){
        const Discord = require("discord.js");
        const { Client } = require('discord.js');
        const bot = require("path_to_index.js")
        const token = require("path_to_your_token");
        bot.login(token.login_token);
        //token_login is how I stored my token to login the bot
        let Prayer = message.member.user.tag;
            async function SendingPray() {
                const Yuuki = await bot.users.fetch('ID_wanted').catch(err => {
                    console.error(err);
                    //means the user id is invalid
                });
                Yuuki.send("My goddess, " + Prayer + " has sent you a pray!").catch(console.error);
            };
            SendingPray();
        message.reply("your pray has been sent. The goddess will read your pray and decide your fate!");
    }
}
let Prayer=message.member.user.tag;
bot.users.cache.get(“我的id”).send(“我的女神,“+Prayer+”向你发送了一个祈祷!”);
但是,我得到了这个错误:

TypeError:无法读取未定义的属性“send”
我不知道为什么它会这样说,因为它也适用于其他人。有人能帮我吗

编辑:

新代码现在正在使用中

const Discord=require(“Discord.js”);
const bot=new Discord.Client();
让祈祷=message.member.user.tag;
异步函数SendingPray(){
消息。回复(“Test3”);
const Yuuki=wait bot.users.fetch('715912580127785060');
消息。回复(“Test4”);
console.log(Yuuki);
消息。回复(“Test5”);
Yuuki.send(“测试”);
消息。回复(“Test6”);
};
发送祈祷();
留言。回复(“你的祈祷已经发出。女神会阅读你的祈祷并决定你的命运!”);
它可以到达Test3,但在测试4之后,它就不会出现,Yuuki也不会被记录

结果: 特别感谢@Karizma与我一起解决这个问题

在index.js的末尾必须说

module.exports = bot;
而pray.js(使用命令处理程序)有以下代码:

module.exports = {
    name: 'pray',
    description: 'Pray to the goddess!',
    usage: '[command name]',
    execute(message, args){
        const Discord = require("discord.js");
        const { Client } = require('discord.js');
        const bot = require("path_to_index.js")
        const token = require("path_to_your_token");
        bot.login(token.login_token);
        //token_login is how I stored my token to login the bot
        let Prayer = message.member.user.tag;
            async function SendingPray() {
                const Yuuki = await bot.users.fetch('ID_wanted').catch(err => {
                    console.error(err);
                    //means the user id is invalid
                });
                Yuuki.send("My goddess, " + Prayer + " has sent you a pray!").catch(console.error);
            };
            SendingPray();
        message.reply("your pray has been sent. The goddess will read your pray and decide your fate!");
    }
}

问题是,在7-9中添加代码,通过新文件重新定义bot时,无法获取ID,因为获取用户时必须调用
.catch
,以防失败

异步函数SendingPray(){ 消息。回复(“Test3”); const Yuuki=wait bot.users.fetch('715912580127785060').catch(err=>{ 控制台错误(err); //表示用户id无效 }); 消息。回复(“Test4”); console.log(Yuuki); 消息。回复(“Test5”); Yuuki.send(“测试”); 消息。回复(“Test6”); };
我已经在discord上测试了id,它似乎是无效的。

用更新的代码更新帖子,不要评论它。我的身份证不对。但是怎么做呢?我用鼠标右键单击自己并复制了我的ID。请将我添加到Discord中,以便我们可以计算出我的ID?以前从未出现过此问题。错误消息如下:
请求使用令牌,但客户端无法使用令牌。
是的,将我添加到discord上,以便我们可以更轻松地解决此问题,Karizma 0007此代码是在
消息
处理程序中还是在文件中类似于此?因为如果它不在
消息
事件处理程序中,那么
消息
变量是未定义的,您应该在消息处理程序中获得未处理的promise rejectionIts。