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

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

Discord.py 在 message.content 中使用列表?

Discord.py 在 message.content 中使用列表?

嗶嗶one 2023-12-09 15:58:26
@bot.eventasync def on_message(message):    wordfilter = ['badword', 'anotherone', 'and the last one']    if wordfilter in message.content:        await message.delete()錯(cuò)誤:Traceback (most recent call last):  File "C:path/client.py", line 333, in _run_event    await coro(*args, **kwargs)  File "C:path/combot.py", line 34, in on_message    if wordfilter in message.content:TypeError: 'in <string>' requires string as left operand, not list我想要一個(gè)單詞過濾器,里面有大量單詞,所以我喜歡有一個(gè)列表,我可以在其中添加所有單詞(稍后甚至可以使用 Discord 的命令)。但我真的不知道如何讓它發(fā)揮作用。
查看完整描述

1 回答

?
萬千封印

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

你無法檢查列表是否在字符串中,你做錯(cuò)了。你想做的是,if message.content in wordfilter但這也是行不通的。您需要獲取消息中的每個(gè)單詞,然后檢查其中一個(gè)單詞是否在其中wordfilter,并且您還需要wordfilter在事件之外創(chuàng)建列表,這樣就不會(huì)每次都創(chuàng)建新列表,并且可以使您的代碼更加優(yōu)化。所以你可以簡單地用一行來完成:


wordfilter = ['badword', 'anotherone', 'and the last one']

@bot.event

async def on_message(message):

    [await message.delete() for word in message.content.split(' ') if word in wordfilter]

因此,它會(huì)將您的消息內(nèi)容從空格中分離出來,并檢查其中一個(gè)單詞是否在單詞過濾器中。如果是,它將刪除該消息。


查看完整回答
反對(duì) 回復(fù) 2023-12-09
  • 1 回答
  • 0 關(guān)注
  • 127 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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