我正在尝试让我的机器人进行设置,但是它给了我Cannot read property 'setActivity' of null
。这是代码的一部分:
bot.login(token);
bot.user.setActivity('activity', { type: 'WATCHING'})
告诉我是否需要其他解决方法。 谢谢!
答案 0 :(得分:3)
这是因为您的机器人还没有准备好。
尝试将您的函数放入如下所示的就绪事件中:
var query = from product in dbContext.Products
join eventProduct in dbContext.EventProducts
on new { pIndex = product.index, eIndex = currentEvent.index }
equals new { pIndex = eventProduct.Product.index, eIndex = eventProduct.Event.index } into temp
from eventProduct in temp.DefaultIfEmpty()
select new Associations.ProductEventProduct {
Product = product,
EventProduct = eventProduct
};
var dataSource = query.ToList();
foreach (Associations.ProductEventProduct entry in dataSource)
{
if (entry.EventProduct == null)
{
entry.EventProduct = new EventProduct
{
Product = entry.Product,
Event = currentEvent,
quantity_allocated = 0,
quantity_sold = 0,
quantity_sampled = 0
};
}
}
顺便确保将bot.once('ready', () => {
bot.user.setActivity('activity', { type: 'WATCHING'});
});
部分放在后面(例如,在文件的最后一行)