Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

How to pass the answer for a discord bot from a json file with variables?

I want to have a .json file where I store all the data about the commands and the answers. Is it possible, to convert {"message": "'<@' + msg.mention.members.first().id + '>'"} the message with all its variables so that discord can understand it when calling msg.channel.send? What I have so far is:

msg.channel.send(commands[i].message);

But Discord displays the message instead of interpreting it. Is there any way of doing so?

question from:https://stackoverflow.com/questions/65870971/how-to-pass-the-answer-for-a-discord-bot-from-a-json-file-with-variables

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

1 Answer

0 votes
by (71.8m points)

Found the answer myself:

msg.channel.send(eval(commands[i].message));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...