python - 我如何获得不和谐消息的作者,然后给他发私信?
问题描述
我如何扫描消息中的单词,如果消息包含该单词,DM 消息的作者?这是到目前为止的代码 -
@client.event
async def on_message(message):
word_list = ['Idiot','noob','dumb']
for word in word_list:
if word in message.content:
if message.author == 'ClientUser':
return
member: discord.member
member = message.author.name
channel = await member.create_dm()
await channel.send(f'Please do not say this word - {word}')
解决方案
我们可以通过获取用户message.author
并向该特定用户发送消息,我们可以通过
await message.author.send(f'Please do not say this word - {word}')
但我们只需要检查成员而不是机器人消息!所以我们这样做
if message.author.bot != True:
await message.author.send(f'Please do not say this word - {word}')
推荐阅读
- laravel - 在 Dusk 测试中,日期字段始终采用美国格式
- c++ - 什么时候可以在 C++ 中意外更改变量的值?
- reactjs - 与 Gatsby 和 Bulma 反应 - 列不水平
- xamarin.forms - 将 TextField 绑定到 Xamarin.Forms 中的 Int 属性
- pandas - 如何查找列连续月数为 6 的索引?
- html - 位置:修复了 Safari 与 Chrome 处理方式不同的问题
- javascript - 旋转时将元素指向圆心(CSS / JS)
- asp.net - 如何将 SQL 获取到数据传输对象?
- javascript - Handllebar 助手返回 href 的附加窗口 url 路径
- typescript - 如何在带有 Typescript 项目的 React Native 中使用 AWS Amplify?