如何在 discord.js (v13) 中为 Bot 的代码块使用语法高亮显示?
How to use syntax highlighting for code Blocks for Bot in discord.js (v13)?
我正在尝试使用机器人在 discord 中创建一个可访问的终端。此命令的代码是:
const { Client, Message, MessageEmbed } = require("discord.js");
const child = require("child_process");
module.exports = {
name: "terminal",
/**
* @param {Client} client
* @param {Message} message
* @param {String[]} args
*/
run: async (client, message, args) => {
if (message.author.id !== "") return;
const command = args.join(" ");
const errorCommand = new MessageEmbed();
errorCommand
.setColor("RED")
.setDescription("Please specify a command to execute");
if (!command) return message.reply({ embeds: [errorCommand] });
child.exec(command, (err, res) => {
if (err) return console.log(err);
message.channel.send(` \`\`\`${res.slice(0, 2000)}\`\`\` `, {
code: "js",
});
});
},
};
当我 运行 命令时,代码块中不显示语法突出显示。我附上了我的意思的图片。
Image 1
Image 2
我找到了答案。很抱歉给您带来不便post,如果有人需要答案,那就是:
const { Client, Message, MessageEmbed } = require("discord.js");
const child = require("child_process");
module.exports = {
name: "terminal",
/**
* @param {Client} client
* @param {Message} message
* @param {String[]} args
*/
run: async (client, message, args) => {
if (message.author.id !== "") return;
const command = args.join(" ");
const errorCommand = new MessageEmbed();
errorCommand
.setColor("RED")
.setDescription("Please specify a command to execute");
if (!command) return message.reply({ embeds: [errorCommand] });
child.exec(command, (err, res) => {
if (err) return console.log(err);
const jsString = "const value = true;";
message.channel.send(` \`\`\`js\n${res.slice(0, 2000)}\`\`\` `);
});
},
};
如果您想使用另一种语言语法突出显示,您只需将此处 message.channel.send(` \`\`\`js\n${res.slice(0, 2000)}\`\`\` `);
的 js
替换为您的偏好即可。
我正在尝试使用机器人在 discord 中创建一个可访问的终端。此命令的代码是:
const { Client, Message, MessageEmbed } = require("discord.js");
const child = require("child_process");
module.exports = {
name: "terminal",
/**
* @param {Client} client
* @param {Message} message
* @param {String[]} args
*/
run: async (client, message, args) => {
if (message.author.id !== "") return;
const command = args.join(" ");
const errorCommand = new MessageEmbed();
errorCommand
.setColor("RED")
.setDescription("Please specify a command to execute");
if (!command) return message.reply({ embeds: [errorCommand] });
child.exec(command, (err, res) => {
if (err) return console.log(err);
message.channel.send(` \`\`\`${res.slice(0, 2000)}\`\`\` `, {
code: "js",
});
});
},
};
当我 运行 命令时,代码块中不显示语法突出显示。我附上了我的意思的图片。
Image 1
Image 2
我找到了答案。很抱歉给您带来不便post,如果有人需要答案,那就是:
const { Client, Message, MessageEmbed } = require("discord.js");
const child = require("child_process");
module.exports = {
name: "terminal",
/**
* @param {Client} client
* @param {Message} message
* @param {String[]} args
*/
run: async (client, message, args) => {
if (message.author.id !== "") return;
const command = args.join(" ");
const errorCommand = new MessageEmbed();
errorCommand
.setColor("RED")
.setDescription("Please specify a command to execute");
if (!command) return message.reply({ embeds: [errorCommand] });
child.exec(command, (err, res) => {
if (err) return console.log(err);
const jsString = "const value = true;";
message.channel.send(` \`\`\`js\n${res.slice(0, 2000)}\`\`\` `);
});
},
};
如果您想使用另一种语言语法突出显示,您只需将此处 message.channel.send(` \`\`\`js\n${res.slice(0, 2000)}\`\`\` `);
的 js
替换为您的偏好即可。