【问题标题】:Can I make a discord.py bot with ads link block and give them blacklist role [closed]我可以制作一个带有广告链接块的 discord.py 机器人并赋予他们黑名单角色[关闭]
【发布时间】:2021-09-08 09:36:11
【问题描述】:

根据我的主题,我想制作一个机器人,它的功能是可以删除广告链接并将黑名单角色授予发送链接的人

【问题讨论】:

    标签: discord.py


    【解决方案1】:

    此代码应该适合您。如果您想将更多的单词/句子添加到黑名单中,您只需在列表中输入它们。您还必须输入黑名单角色的 ID。

    @commands.Cog.listener()
    async def on_message(self, msg):
        Blacklist= ["https://discord.gg/", ".com"]
        for black in Blacklist:
            if black .lower() in msg.content.lower():
                await msg.delete()
                role = get(msg.guild.roles, id=role_id)
                await msg.author.add_roles(role)
                await msg.channel.send(f"You just Used an Blacklisted Word.")
    

    【讨论】:

    • 我在 vscode 中遇到了这个问题:“get”未定义 Pylance(reportUndefinedVariable) 并在 pycharm 中得到了这个:未解析的引用“get”,未使用参数“self”值,函数中的变量应该小写
    • 你需要先安装并导入 Discord.utils pypi.org/project/DiscordUtils
    • 另外如果你不使用Cogs,你需要删除self并将@commands.Cog.listener()替换为@client.event
    • 我仍然得到:“get”未定义 Pylance(reportUndefinedVariable)
    • 你还需要"from discord.utils import get"
    猜你喜欢
    • 2020-10-04
    • 2021-02-21
    • 2019-06-01
    • 2019-10-28
    • 2021-09-20
    • 1970-01-01
    • 2021-03-26
    • 2021-04-12
    • 2020-09-19
    相关资源
    最近更新 更多