使用 Discord.J 编辑嵌入字段
Posted
技术标签:
【中文标题】使用 Discord.J 编辑嵌入字段【英文标题】:Editing an Embed Field with Discord.J 【发布时间】:2020-08-09 06:36:20 【问题描述】:我想做以下事情:
我将使用命令 (!setupembed) 创建一个嵌入 这将在特定频道中创建嵌入并添加对嵌入的反应。 有一个名为 Codes 的嵌入字段,它计算 .txt 的行数
每当用户对嵌入的表情符号做出反应时,他都应该得到一个带有存储在 .txt 中的代码的 DM 现场计数器:代码应减少 1 到目前为止,这就是我的代码:
bot.on("ready", () =>
console.log("Succesfully started the tools bot");
)
bot.on("message", message=>
let args = message.content.substring(prefix.length).split(" ");
var mcodes = fs.readFileSync('./text.txt').toString().split("\n").length;
const embed = new Discord.MessageEmbed().setTitle("Codes").setDescription("Pls React").addField("Instock", "`" + mcodes + "`")
switch(args[0])
case "code":
let codetext = message.content.replace(prefix + "code", "")
fs.appendFile("./text.txt", codetext + "\n",(err)=>
if (err) throw err;
message.channel.send("message written")
)
const newembed = new Discord.MessageEmbed()
.setTitle("CODES")
.addField("Instock", "`" + snscodes + 1 + "`")
message.edit(embed)
break;
case "getcode":
let getcode = fs.readFileSync("./text.txt", "utf8", (err)=>
if (err) throw err;
)
var code_array = getcode.split("\n")
message.channel.send(code_array[0])
let spliced = code_array.splice(0);
fs.writeFile("./text.txt", "utf8", (err)=>
if (err) throw err;
)
break;
case "setupembed":
bot.channels.cache.get("698221179810349187").send(embed).then(sent =>
sent.react("????️")
)
break;
)
```
I already tried to write the part bymyself but i cant get it to work thats my attempt: (see answers)
【问题讨论】:
【参考方案1】: case "setupembed":
const embed = new Discord.MessageEmbed()
.setTitle("Codes")
.addField("CODES", "`" + mcodes + "`")
bot.channels.cache.get("698221179810349187").send(embed)
.then(sent =>
sent.react("?️")
)
const filter = (reaction, user) =>
return reaction.emoji.name === '?️' && user.id === message.author.id;
;
const collector = message.createReactionCollector(filter, time: 15000 );
collector.on('collect', (reaction, reactionCollector) =>
let getcode = fs.readFileSync("./text.txt", "utf8", (err)=>
if (err) throw err;
)
var code_array = getcode.split("\n")
message.author.send(code_array[0])
let spliced = code_array.splice(0);
fs.writeFile("./text.txt", "utf8", (err)=>
if (err) throw err;
)
);
collector.on('end', collected =>
console.log(`Collected $collected.size items`);
);
break;
```
【讨论】:
以上是关于使用 Discord.J 编辑嵌入字段的主要内容,如果未能解决你的问题,请参考以下文章
有没有办法使用 quick.db 制作 discord.js 日志系统