Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用用户ID的Discord.JS Avatar命令_Javascript_Node.js_Discord_Discord.js - Fatal编程技术网

Javascript 使用用户ID的Discord.JS Avatar命令

Javascript 使用用户ID的Discord.JS Avatar命令,javascript,node.js,discord,discord.js,Javascript,Node.js,Discord,Discord.js,我想使用用户id/提及的化身命令。我可以使用提及,但是我不能使用用户ID 这是我目前的代码: const Discord=require'Discord.js'; module.exports={ 名称:'阿凡达', 描述:'阿凡达', 别名:['av'], 冷却时间:5, 异步执行消息,args{ 让member=message.indications.users.first | | message.guild.members.cache.getargs[0]| | message.autho

我想使用用户id/提及的化身命令。我可以使用提及,但是我不能使用用户ID

这是我目前的代码:

const Discord=require'Discord.js'; module.exports={ 名称:'阿凡达', 描述:'阿凡达', 别名:['av'], 冷却时间:5, 异步执行消息,args{ 让member=message.indications.users.first | | message.guild.members.cache.getargs[0]| | message.author; 让avatar=member.displayAvatarURL{size:1024,dynamic:true}; const embed=new Discord.MessageEmbed .setAuthoravatar,message.username .setTitle`Avatar` .setImageavatar .setColorBLACK .setAuthormember.username、头像、头像; message.channel.sendebed; }, }; 无论何时运行此代码,我都会收到以下错误:

Test Bot v1 ready!
(node:835) UnhandledPromiseRejectionWarning: TypeError: member.displayAvatarURL is not a function
    at Object.execute (/home/runner/no/commands/ping.js:13:28)
    at Client.<anonymous> (/home/runner/no/index.js:106:13)
    at Client.emit (events.js:314:20)
    at Client.EventEmitter.emit (domain.js:483:12)
    at MessageCreateAction.handle (/home/runner/no/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (/home/runner/no/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (/home/runner/no/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (/home/runner/no/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (/home/runner/no/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
    at WebSocket.onMessage (/home/runner/no/node_modules/ws/lib/event-target.js:132:16)
(node:835) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:835) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
该方法仅对用户可用。这意味着它可以处理message.indications.users.first或message.author,因为它们返回用户,但不能处理message.guild.members.cache.getargs[0],因为它返回GuildMember

如果存在args[0]且members.cache.get返回一个GuildMember,请获取其属性,以便以后也可以获取其头像

以下工作很好:

让user=message.notices.users.first ||message.guild.members.cache.getargs[0]?.user ||message.author; 让avatar=user.displayAvatarURL{size:1024,dynamic:true}