我正在制作一个正在更改行会频道名称的机器人。但是,当我使用node.js运行程序时,我的函数返回了未定义的值,这是一个问题。但是在功能上一切都是真的。
function fetchdataFromApiUsd(moneykind){
fetch("https://api.exchangeratesapi.io/latest?base="+moneykind)
.then((resp) => resp.json())
.then((data) =>{
const sonuc = data.rates
console.log(sonuc.TRY);//The values come true.
return sonuc.TRY;
} )
.catch(err => console.log(err));
}
但是当我这样打电话
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('Pong!');
}
if(msg.content==='hiThere'){
const currentusd=fetchdataFromApiUsd("USD");
const currenteuro=fetchdataFromApiUsd("EUR");
let myGuild = client.guilds.cache.get(msg.guild.id)
let channel = myGuild.channels.cache.get('297798780592324610')
let channel1 = myGuild.channels.cache.get('297798809533022208')
channel.setName('1 Dolar = '+currentusd) //Returns undefined
channel1.setName('1 Euro = '+currenteuro)//Returns undefined
.catch()
console.log(currentusd) //Returns undefined
console.log(currenteuro) //Returns undefined
}
});
答案 0 :(得分:0)
我的错误是异步变量。我用大括号定义变量。好了另外,您应该在函数中调用这些变量以再次定义更新值。
min_value = None
max_value = None
for i in range(number_of_stats):
stat_score = int(input('Please enter the stats #%s: ' % (i+1)))
stat_sum += stat_score
if min_value is None or stat_score < min_value:
min_value = stat_score
if max_value is None or stat_score > max_value:
max_value = stat_score