Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
118 views
in Technique[技术] by (71.8m points)

How to add line to a txt file in discord.js

I have a logging txt file for my bans and kicks to keep track of them in my dc bot.

The log file gets really messy after the first ban because i do not know how to yet the logs to separate lines in the file.

Does anyone know how to do that?

question from:https://stackoverflow.com/questions/65641086/how-to-add-line-to-a-txt-file-in-discord-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Okay so as you have not provided any code, I can just guess how you are doing it. Lets say you have a variable let str = "" where you add your bans to. In this case you can simply do:

str += `Banned/Kicked ${user.tag}, because ${reason}.
`;

would add a new line for each new ban/kick. Let's say we have two banned users. The name of the first one is Example#0001 and the reason was Test. The name of the second user is Example#0002 and the reason was Test2. This would be the output:

Banned/Kicked Example#0001, because Test.
Banned/Kicked Example#0002, because Test2.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...