DM Join消息在Discord C#Bot中不起作用

时间:2019-12-29 06:04:47

标签: c# discord

我遇到错误,当我尝试为欢迎消息创建DM通道时出现错误:无法通过引用转换,装箱转换,拆箱转换,换行转换或空类型转换将类型转换为。

这是我的代码。

        {
            var channel = _client.GetDMChannelsAsync() as SocketDMChannel;
            await channel.SendMessageAsync("Welcome to Noice Discord!");
        }

在我的handlecommandsasync函数中,我还在底部。 _client.UserJoined += AnnounceJoinedUser;

任何帮助都会很好,因为我真的被困在这里。

1 个答案:

答案 0 :(得分:0)

首先,似乎您使用的是图书馆的过时版本,建议您进行更新。

第二,假设代码中的const saveOrder = async () => { try { this.setState({ isLoading: true }); let push = await promisifyThenable(ref.push( { buildingNumber, problemDescription, date, time, coordinate, categoryName, serviceDB, status: 'pending', })); let key = push.key; this.setState({ snapshotKey: key }); // thats get dawnload url await this._SaveImagesToFirebase(key); if (childData.length > 0) { // thats get dawnload url await this._SaveRecordToFirebase(key); } } catch (someError) { console.log('got some error: ', someError); } } // Second main function saveOrderForProvider = () => { const { isModalVisible, ...OrderData } = this.state; console.log('RestOrder', OrderData); const ref = database().ref( `Providers/CategoriesOrders/${OrderData.serviceDB}`, ); return this.promisifyThenable(ref.push({ ...OrderData, status: 'pending', })); console.log('RestOrder', OrderData); }; _SaveRecordToFirebase = key => { const { uid, childData } = this.state; let path = 'record_' + new Date().getTime() + '.aac'; const users = database().ref(`/usersOrders/${uid}/${key}`); const ref = storage().ref(`users/${uid}/usersRecords/${path}`); return this.promisifyThenable(ref.putFile(childData[0].filePath)).then(async done => { console.log('Done upload record', done); await ref.getDownloadURL().then( record => { console.log('recordURI', record); this.setState({ recordForProvider: record }); users.update({ records: { uri: record }, }); }, error => console.log(error), ); }); }; promisifyThenable = thenable => new Promise((resolve, reject) => thenable.then(resolve).catch(reject)); 是您的_client事件处理程序提供的SocketGuildUser(考虑给它起一个更好的名字,以后在寻求帮助时,请提供所有所需的代码),则无需将其强制转换为任何内容,而是要等待它。
而且您不应该使用UserJoined
(请注意,复数形式,也许您是无意间这样做的?将其删除)

因此,这是您最终想要得到的(在Discord.NET的最新版本上)

GetDMChannelsAsync

或者,如果您更改为该库的最新版本,则该方法将重命名为var channel = await _client.GetDMChannelAsync(); await channel.SendMessageAsync("Welcome to Noice Discord!");