gpt4 book ai didi

javascript - 如何张贴提及松弛传入的 webhooks

转载 作者:行者123 更新时间:2023-11-30 19:27:03 25 4
gpt4 key购买 nike

我发送到传入 webhook 的提及呈现为纯文本。

注意:使用请求包发送post请求。

尝试了以下方法:

发送提及为 <@userid>

结果:<@userid>//作为纯文本

request.post(
`${channels[message.channel.name]}`,
{
json: {
text:
'To: ' + mapDiscordToSlackNames(message.mentions.users) + '\n' +
'Discord channel: #' + message.channel.name + '\n' +
'Link: <' + message.url + '|Link to post>' + '\n' +

结果:收件人:@soda//作为纯文本而不是向@soda 用户提及

完整代码

// require the discord.js module
const Discord = require('discord.js');
const devs = require('./devs.json');
const channels = require('./channels.json');
const dotenv = require('dotenv');
const path = require('path');
var request = require('request');

dotenv.load({
path: path.join(__dirname, `.env`),
silent: true
});

// create a new Discord client
const client = new Discord.Client();

// Map discord usernames of devs to slack usernames
function mapDiscordToSlackNames(discordUsers) {
return discordUsers.map( user => {
return '@' + devs[user.username];
})
}

// when the client is ready, run this code
// this event will only trigger one time after logging in
client.once('ready', () => {
console.log('Discord Connected!');
});

// on message on discord
client.on('message', message => {

console.log(channels[message.channel.name]);
request.post(
`${channels[message.channel.name]}`,
{
json: {
text:
'To: ' + mapDiscordToSlackNames(message.mentions.users) + '\n' +
'Discord channel: #' + message.channel.name + '\n' +
'Link: <' + message.url + '|Link to post>' + '\n' +
'Original Message: \n' +
'\t"' + message.author.username + ': ' + message.cleanContent + '"\n' +
`Attachements: ${message.attachments.map(attachment => attachment.url)}`
},
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
);
});

// login to Discord with app's token
client.login(process.env.DISCORD_TOKEN);

devs 是一个 json 对象,它返回对应于 discord 用户名的 slack 用户名。

最佳答案

原来我是通过转义字符串中的“<”和“>”来发送用户标识的,例如

'<@userid>' 因此它以纯文本形式传递。

To mention someone in slack do 'To: <@' + userid + '>'

The userid starts with U and can be found after the team/ in url of your workspace eg: Cxxxxx/team/Uxxxxx/

关于javascript - 如何张贴提及松弛传入的 webhooks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56796217/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com