我正在尝试为我的discord机器人开发一个更详细的日志系统,这就是我目前所拥有的:
client.on('message', message => {
if (message.author.bot) return; //don't log its own messages
const channel = client.channels.cache.get('805457298867879936'); //sent logs to this channel
channel.send(
`${message.author} in ${message.channel} of ${message.guild} said ${message.content}`, //log in discord channel
);
console.log(
`${message.author.tag} in #${message.channel.name} of ${message.guild.name} said: ${message.content}`, //log in console
);
client.login(token); //login此代码记录机器人可以在特定通道和我的控制台中看到的任何发送的消息。但是,我也希望有一个消息链接到已发送的消息。例如,这是我当前记录的:Kingamezz#02XX in #testing of Testing Server said: test,我想要的是:Kingamezz#02XX in #testing of Testing Server said: test (https://discord.com/channels/763786268181397524/805457298867879936/805502804134330448),这样我就可以直接跳到消息了。
我不知道如何获取消息的消息链接,discordjs文档似乎没有任何关于消息链接的内容。我试过了:
channel.send(
"https://discord.com/channels/" + guild.id + "/" + message.id
)但这会导致“行会没有定义”。我这样做对吗?
发布于 2021-02-01 02:51:44
您可以使用Message的.url属性来获取可以跳转到的url,如下所示:
channel.send(message.url);文档:https://discord.js.org/#/docs/main/master/class/Message?scrollTo=url
另外,你当前代码不能工作的原因是没有行会对象,只有消息对象。因此,您必须首先从消息对象中获取公会,才能访问公会属性。所以,如果你想继续使用当前的代码,你也可以这样做:
channel.send(
"https://discord.com/channels/" + message.guild.id + "/" + message.guild.id
)然而,对于第二种解决方案需要注意的一件事是,如果消息是直接消息,它可能会出错,因为该消息不是在行会中发送的。
https://stackoverflow.com/questions/65982977
复制相似问题