当有人加入时创建规则协议

2024-03-12

我想要一个机器人将新成员设置为只能查看一个频道并且必须就规则达成一致才能使用服务器的角色。我已经写了这个来做到这一点,但我不断收到此错误。

Ignoring exception in on_member_join
Traceback (most recent call last):
  File "C:\Users\ezter\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 307, in _run_event
    yield from getattr(self, event)(*args, **kwargs)
  File "D:\programing\Discord Bots\Osis Nation\Start.py", line 31, in on_member_join
    role = discord.utils.get(bot.roles, name="Default")
  File "C:\Users\ezter\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 296, in __getattr__
    raise AttributeError(msg.format(self.__class__, name))
AttributeError: '<class 'discord.ext.commands.bot.Bot'>' object has no attribute 'roles'

我用这段代码来做到这一点

#Welcomer
@bot.event
async def on_member_join(member):
    print("A member just joined and his name is" + member.name)
    mid = member.id
    role = discord.utils.get(bot.roles, name="Default")
    role3 = discord.utils.get(member.server.roles, id="<479670838648635392>")
    role2 = discord.utils.get(member.server.roles, id="<479692108953944081>")
    await bot.add_roles(member, bot.get_)

    Rules = "1. Do not DM the Owner or any other staff unless they have DMed you first! \n 2. Be kind, \n 3. Use common sense, \n 4. No swearing, \n 5. No racism or bullying, \n 6. No advertising, \n 7. Do not chat in #music Text or Voice channels, \n 8. Do not spam #applications if your application is accepted or denied! This is only to be used for submitting and staff members replying to the application. \n 9. Do not use or abuse bot commands you should not be using! \n 10. Do not @ any staff members unless it is an emergency.  "

    await bot.send_message(bot.get_channel('479685091749134346'), 'Hello <@%s>, Welcome to Osis Nation, please read all the rules carefully' % (mid))
    await bot.send_message(bot.get_channel('479685091749134346'), (Rules))
    await bot.send_message(bot.get_channel('479685091749134346'), 'If you agree write !Agree. If you do not agree write !Decline')

    if member.content.upper().startwith("!Agree"):
        await bot.send_message(bot.get_channel('479685091749134346'), 'You will be redirected to the server in 5 seconds')
        time.sleep(5)

        await bot.remove_roles(member, role)

我用这段代码做到了

    #Welcomer
@bot.event
async def on_member_join(member):
    print("A member just joined and his name is" + member.name)
    mid = member.id
    role = discord.utils.get(member.server.roles, name="Default")
    await bot.add_roles(member, role)

    Rules = "1. Do not DM the Owner or any other staff unless they have DMed you first! \n 2. Be kind, \n 3. Use common sense, \n 4. No swearing, \n 5. No racism or bullying, \n 6. No advertising, \n 7. Do not chat in #music Text or Voice channels, \n 8. Do not spam #applications if your application is accepted or denied! This is only to be used for submitting and staff members replying to the application. \n 9. Do not use or abuse bot commands you should not be using! \n 10. Do not @ any staff members unless it is an emergency.  "

    await bot.send_message(bot.get_channel('479685091749134346'), 'Hello <@%s>, Welcome to Osis Nation, please read all the rules carefully' % (mid))
    await bot.send_message(bot.get_channel('479685091749134346'), (Rules))
    await bot.send_message(bot.get_channel('479685091749134346'), 'If you agree write !Agree. If you do not agree write !Decline')
@bot.event
async def on_message(message):
    if message.content.upper().startswith("!AGREE"):
        await bot.send_message(bot.get_channel('479685091749134346'), 'You will be redirected to the server in 5 seconds')
        time.sleep(5)
        role = discord.utils.get(message.server.roles, name="Default")
        await bot.remove_roles(message.author, role)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

当有人加入时创建规则协议 的相关文章

随机推荐

  • CMYK颜色直接转HSV颜色

    如何将HSV颜色直接转换为CMYK颜色 提及做到这一点的 JavaScript 库会加分 我只见过将 HSV 转换为 RGB 然后将 RGB 转换为 CMYK 的解决方案 我知道的唯一解决方案是转换为 RGB 作为中间层 然后将其转换为您想
  • 配置 WCF 服务以接受不合格参数

    我的 WCF 服务无法识别以不合格形式发送的请求参数值 而是替换为默认值 例如 此请求将产生 您输入 21 的结果
  • 如何重新配置​​ Meteor 的 Facebook 账户,或者 Meteor 的 Facebook 配置在哪里?

    流星的accounts facebook包的设置非常容易 为了输入 Facebook 应用程序 ID 和秘密令牌 我在浏览器中加载了 Meteor Web 应用程序 单击登录按钮 然后单击 配置 Facebook 它要求我提供应用程序 ID
  • C# ASP.NET 列表视图

    我正在尝试创建一个包含多个产品列表的视图 下面的示例展示了产品列表的外观 我不确定是否应该使用表格并为每个新产品或其他内容创建一个新表格 我不是一个很好的 ASP NET 开发人员 我不知道如何解决这个问题 基本上 如果我有 10 个结果
  • JS中的罗马到整数为什么只转换第一个字符

    我尝试解决Leedcode问题13 问题是给定一个罗马数字 将其转换为整数 输入保证在1到3999的范围内 这是我的代码 我想知道为什么它只将罗马数字中的第一个字符转换为整数 var romanToInt function s var re
  • 使用 mod_rewrite 将所有流量重定向到 index.php

    我正在尝试构建一个 url 缩短器 并且我希望能够在域之后立即获取任何字符并将它们作为变量 url 传递 例如 http google com asdf http google com asdf 会成为 http www google co
  • 从数据库中选择最受欢迎的地点的算法

    我们有一个包含地点数据库的网站 对于每个地方 我们的用户都可以执行我们记录的以下操作之一 查看 查看其个人资料 评级 按 1 5 星的等级对其进行评级 审查 审查它 已完成 标记他们已经去过那里 愿望清单 标记他们想去那里 最喜欢的 标记这
  • 实体框架,更新前值的触发机制

    EF 中是否有在更新对象值之前具有的内容 例如当实体对象 假设用户 被保存时 我想在更新用户对象值之前了解日志记录的目的 Thanks 如果您与ObjectContext edmx 您可以订阅SavingChanges http msdn
  • 为什么我无法实例化 switch-case 块内的对象

    我的代码有 3 个类 n hexa n octa n bin 代码在这里 switch choice case 1 cin gt gt n n hexa nx n break case 2 cin gt gt n n octa no n b
  • 如何使用 gulp 在浏览器中进行刷新

    我有一个应用程序在 iis 中 它是一个用 angularjs 和 webapi C 2 0 制作的应用程序 我想创建一个任务 在保存任何 js 文件后立即更新浏览器 吞咽版本 3 9 1 gulp task livereload func
  • 尝试在本地环境中调试 LeetCode 答案时出错

    我正在研究 LeetCode 问题199 二叉树右侧视图 https leetcode com problems binary tree right side view 给定二叉树的根 想象自己站在它的右侧 返回您可以看到从上到下排序的节点
  • 无法使用通过 VS2010 发布在 Windows Azure 上发布网站

    当我尝试通过 Visual Studio 2010 在 Windows Azure 上发布我的 Web 应用程序时 我遇到了这个问题 我尝试右键单击项目并选择发布并导入从 Windows Azure 平台下载的发布配置文件 我收到此错误 错
  • 加入多个文件

    我正在使用标准连接命令来连接两个基于column1 的排序文件 命令很简单 join file1 file2 gt output file 但是如何使用相同的技术连接 3 个或更多文件呢 连接 file1 file2 file3 gt 输出
  • 在运行时根据输入从属性文件中获取值 - java Spring

    我的 color properties 文件为 rose red lily white jasmine pink 我需要获取颜色值 String flower runTimeFlower Value flower String colour
  • Playframework 2.0.x 是否支持模板中的

    不知道play 2 0 3及更高版本是否支持else if在视图中 我只读到必须这样编码 if else if else 不敢相信 我在第二个 if 之前使用了 if true else if true else
  • 使用 nltk 没有上下文的词性标记

    有没有一种简单的方法来确定给定单词最可能的词性标签没有上下文使用nltk 或者如果不使用任何其他工具 数据集 我尝试使用 wordnet 但似乎 sysnet 不是按可能性排序的 gt gt gt wn synsets says Synse
  • Android计算器-Editview无法输入小数位

    我是Android代码开发新手 我正在开发一个Android计算器应用程序 不明白为什么两个EditText 第一个输入和第二个输入 不能接受小数位而只能输入整数 附如下是代码 Thanks 主要活动 package com trial j
  • 将 ScriptableObjects 加载到单个预制件/多个预制件的最佳实践是什么?

    脚本化对象 SO 我最近一直在尝试了解 ScriptableObjects 并在 Unity 中建立了一个项目 我只想射击生成的传入敌人 我已经设置了它 这样我就可以通过 SO s 创建不同的敌人 但注意到我仍然需要为每个敌人创建一个预制件
  • 我们可以简化这个字符串编码代码吗

    是否可以将此代码简化为更干净 更快的形式 StringBuilder builder new StringBuilder var encoding Encoding GetEncoding 936 convert the text into
  • 当有人加入时创建规则协议

    我想要一个机器人将新成员设置为只能查看一个频道并且必须就规则达成一致才能使用服务器的角色 我已经写了这个来做到这一点 但我不断收到此错误 Ignoring exception in on member join Traceback most