警告:
(process:3380): GLib-GIO-WARNING **: 12:47:10.778: Unexpectedly, UWP app `HaukeGtze.NotepadEditor_1.795.1.0_x64__6bk20wvc8rfx2' (AUMId `HaukeGtze.NotepadEditor_6bk20wvc8rfx2!notepad') supports 182 extensions but has no verbs
Run Code Online (Sandbox Code Playgroud)
我认为“意外”之前的部分是时间,但是剩下的部分是什么意思?
在开始之前我做的最后一件事是使用npm install canvas --save.
那么我有办法阻止这种情况吗?
我还注意到那里写着 NotepadEditor 但这有什么关系呢?它不会使进程崩溃,似乎不会影响任何东西,但很烦人。
编辑:它是由 require('canvas') 引起的,而不是安装它。那么我怎样才能在不收到警告的情况下要求它呢?
为什么对象属性的反引号语法无效?例如,这是有效的:
\nconst test = {\n "test1": "test2"\n}\nRun Code Online (Sandbox Code Playgroud)\n那么为什么 \xe2\x80\x99 不能有反引号呢?
\nconst test = {\n `test1`: "test2"\n}\n//throws unexpected token error\nRun Code Online (Sandbox Code Playgroud)\n如果可以像这样使用反引号,那将非常有帮助,但我们可以\xe2\x80\x99t。是否有一个简单的替代方案,或者这可能在某些浏览器中有效?
\n我的机器人收到了 403 错误,尽管以前从未发生过,而且代码根本没有改变。
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Bots cannot use this endpoint
---
{
method: 'put',
path: '/applications/---/guilds/---/commands/---/permissions',
code: 20001,
httpStatus: 403,
requestData: { json: { permissions: [Array] }, files: [] }
}
Run Code Online (Sandbox Code Playgroud)
尝试设置fullPermissions却出现 405 错误
DiscordAPIError: 405: Method Not Allowed
---
{
method: 'put',
path: '/applications/---/guilds/---/commands/permissions',
code: 0,
httpStatus: 405,
requestData: {
json: [
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], …Run Code Online (Sandbox Code Playgroud) 我目前正在编写一个不和谐的机器人,并想尝试一下新的交互功能(又名斜杠命令)。
\n我设法让“/test”交互工作,机器人接收命令并执行我的代码(遵循discord.js手册)。现在我知道interaction.commandName命令的名称(在本例中为“test”),但我不\xe2\x80\x99t 似乎能够获取传入的参数。
以下是我的“test.js”,它用于“/test”命令:
\nconst { SlashCommandBuilder } = require(\'@discordjs/builders\');\n\nmodule.exports = {\n data: new SlashCommandBuilder()\n .setName(\'test\')\n .setDescription(\'Test with arguments!\')\n .addStringOption(option =>\n option.setName("device")\n .setDescription("Some argument")\n .setRequired(true)\n .addChoice("Arg A", "A")\n .addChoice("Arg B", "B")\n ),\n async execute(interaction, log) {\n // log is a function to log to a file...\n // Ignore it, since it is not *currently* in use.\n \n return interaction.reply("You selected the argument ????")\n \n // Delete message after 5 seconds\n .then(setTimeout(() => interaction.deleteReply(), 5000));\n },\n};\n …Run Code Online (Sandbox Code Playgroud) 当我使用 Axios 向 api 发出 get 请求时,我在 useEffect 挂钩中遇到无限循环,并且我确信添加第二个选项“[]”会告诉它只运行一次。有什么我遗漏或忽视的吗?console.log 向我显示它正在无限循环。
import React, {useEffect, useState} from 'react';
import axios from 'axios';
import { getCookie } from '../utils/util';
const Details = () => {
const [data, setData] = useState(null);
let country;
const queryURL = `https://restcountries.eu/rest/v2/name/`;
useEffect(() => {
country = getCookie('title');
console.log(country);
axios.get(queryURL + country).then((res) => {
setData(res.data);
}, []);
})
return (
<>
details
</>
)
}
export default Details;
Run Code Online (Sandbox Code Playgroud) 我是一名编程大三学生。我了解 Node.js,并且想编写自己的 Discord 机器人。
我下面写的代码不起作用。你能帮我解决这个问题吗?
const { Client, Intents } = require('discord.js');
const config = require('./config.json');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message=>{
if(!message.content.startsWith(config.prefix) || message.author.bot) return;
const args = message.content.slice(config.prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'ping'){
message.channel.send('pong!');
}
})
client.login(config.token);
Run Code Online (Sandbox Code Playgroud) 一般来说,我对编码很陌生,所以预计会有新手行为。
我的 Discord Bot 通过命令节点上线。我尝试了 !ping 命令,一切正常。但是,当我尝试声明的命令 !play 来播放来自 YT 的视频时,但当我按 Enter 键时,机器人崩溃并显示以下日志:
const connection = await voiceChannel.join();
^
TypeError: voiceChannel.join is not a function
at Object.execute (D:\Discord Bot\commands\play.js:43:48)
at Client.<anonymous> (D:\Discord Bot\main.js:33:41)
at Client.emit (node:events:394:28)
at MessageCreateAction.handle (D:\Discord Bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:18)
at Object.module.exports [as MESSAGE_CREATE] (D:\Discord Bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (D:\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:345:31)
at WebSocketShard.onPacket (D:\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:443:22)
at WebSocketShard.onMessage (D:\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:300:10)
at WebSocket.onMessage (D:\Discord Bot\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (node:events:394:28)
Run Code Online (Sandbox Code Playgroud)
这是主要代码:
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
const prefix = '!';
const …Run Code Online (Sandbox Code Playgroud) 将我的 Discord.js 更新到 v13 时,出现许多错误:
//member.hasPermission is not a function
member.hasPermission("SEND_MESSAGES")
//Cannot send an empty message
channel.send(someEmbed)
//Cannot send an empty message
channel.send({embed: someEmbed})
//Warning: The 'message' event was deprecated, use 'messageCreate' instead
client.on("message", msg => {})
//Cannot send an empty message
channel.send(user)
//[CLIENT_MISSING_INTENTS] Valid intents must be provided for the client
const client = new Client()
//channel.join is not a function
await channel.join()
Run Code Online (Sandbox Code Playgroud)
这些在 v12 中不会发生,那么我该如何在 v13 中修复它们呢?