第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

我不明白我在使用 on_member_join/on_member_remove

我不明白我在使用 on_member_join/on_member_remove

開(kāi)心每一天1111 2021-10-10 14:23:51
我一直在研究用 python 編碼的不和諧機(jī)器人。當(dāng)用戶加入服務(wù)器并離開(kāi)服務(wù)器時(shí),我一直試圖讓我的機(jī)器人說(shuō)出一條消息。但是當(dāng)我測(cè)試它時(shí),我得到了 2 個(gè)錯(cuò)誤,我不明白這些錯(cuò)誤。而且我不確定我做錯(cuò)了什么。如果有人可以幫助解釋這些錯(cuò)誤,并為我的代碼指出正確的方向,我將不勝感激。我研究了discord rewrite api,并與朋友在我的服務(wù)器中對(duì)其進(jìn)行了測(cè)試,當(dāng)時(shí)我遇到了錯(cuò)誤@client.eventasync def on_member_join(member):    channel = member.server.get_channel("499457708978864151")    msg = 'Welcome to the {1.name} Server, {0.mention}'    await client.say(channel, msg.format(member, member.server))@client.eventasync def on_member_remove(member):    channel = member.server.get_channel("499457708978864151")    msg = '{0.mention} has left the server'    await client.say((channel, msg.format(member, member.server)))我希望我的機(jī)器人在他們進(jìn)入服務(wù)器時(shí)說(shuō)歡迎使用(服務(wù)器的名稱)服務(wù)器,@username,當(dāng)用戶離開(kāi)時(shí)@username 已經(jīng)離開(kāi)服務(wù)器,但我收到了這些錯(cuò)誤:TypeError: send_message() takes from 2 to 3 positional arguments but 4 were givendiscord.errors.InvalidArgument: Destination must be Channel, PrivateChannel, User, or Object. Received NoneType這是我的完整追溯Ignoring exception in on_member_joinTraceback (most recent call last):  File "C:\Users\Chris\PycharmProjects\untitled1\venv\lib\site-packages\discord\client.py", line 307, in _run_event    yield from getattr(self, event)(*args, **kwargs)  File "C:/Users/Chris/PycharmProjects/untitled1/RomaniBot.py", line 37, in on_member_join    await client.say(channel, msg.format(member, member.server))  File "C:\Users\Chris\PycharmProjects\untitled1\venv\lib\site-packages\discord\ext\commands\bot.py", line 350, in say    coro = self.send_message(destination, *args, **kwargs)TypeError: send_message() takes from 2 to 3 positional arguments but 4 were givenIgnoring exception in on_member_removeTraceback (most recent call last):
查看完整描述

2 回答

?
慕無(wú)忌1623718

TA貢獻(xiàn)1744條經(jīng)驗(yàn) 獲得超4個(gè)贊

您的代碼的一種簡(jiǎn)單修復(fù)方法是使用 ,而不是client.say使用channel.send。所以


@client.event

async def on_member_join(member):

    channel = member.server.get_channel(499457708978864151)

    msg = 'Welcome to the {1.name} Server, {0.mention}'

    await channel.send(msg.format(member, member.server))

此外,根據(jù)文檔,


get_channel(id)


返回具有以下 ID 的 abc.GuildChannel 或 abc.PrivateChannel。


如果未找到,則返回 None。


所以你沒(méi)有成功選擇頻道。原因是 rewrite 中的 ID 是int,而不是字符串。


查看完整回答
反對(duì) 回復(fù) 2021-10-10
?
慕雪6442864

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊

member.server向您返回成員加入的服務(wù)器。并且您嘗試使用 ID 訪問(wèn)頻道499457708978864151,這肯定不會(huì)在頻道使用 ID 所在的服務(wù)器之外的其他服務(wù)器中工作499457708978864151,因此您也必須讓服務(wù)器client.get_server("ID")執(zhí)行此操作。


查看完整回答
反對(duì) 回復(fù) 2021-10-10
  • 2 回答
  • 0 關(guān)注
  • 228 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)