简体   繁体   English

我可以将 discord 机器人的控制台日志打印到 discord.js 中的特定通道吗?

[英]Can I print the console log of my discord bot into a specific channel in discord.js?

I am making a discord bot which will send a dm to a particular user if the staff types ",ping<@mentionusername>" so.我正在制作一个 discord 机器人,如果员工键入“,ping<@mentionusername>”,它将向特定用户发送 dm。 i want my bot to record its console logs of node.js in a particular channel so that other staff members can also see the logs instead of just the developer?我希望我的机器人在特定频道中记录其 node.js 的控制台日志,以便其他工作人员也可以看到日志,而不仅仅是开发人员? Can anyone share with me the code for it?任何人都可以与我分享它的代码吗?

Maybe you can create your own log function, or hooking the console.log function.也许您可以创建自己的日志 function,或者挂钩console.log function。

Simple way:简单的方法:

function log(msg) 
{
    console.log(msg);
    const channel = member.guild.channels.cache.find(ch => ch.name === 'log');
    if (!channel) return;
    channel.send(msg);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM