[英]I am struggling with dming members with a certain role in discord.py
Here's the code这是代码
import discord
import random
from discord.ext import commands, tasks
from discord.utils import get
@client.command()
async def play(ctx):
red_role = discord.utils.get(ctx.message.guild.roles, name="Red")
blue_role = discord.utils.get(ctx.message.guild.roles, name="Blue")
red_boss_role = discord.utils.get(ctx.message.server.roles, name="Red Boss")
blue_boss_role = discord.utils.get(ctx.message.server.roles, name="Blue Boss")
and then DMing然后DMing
for i in red_boss_role_id.members:
await i.send("🔴" + str(red_agents))
for i in blue_boss_role_id.members:
await i.send("🔵" + str(blue_agents))
I have already tried same thing with IDs, but no progress It says the error我已经用 ID 尝试过同样的事情,但没有进展它说错误
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Message' object has no attribute 'server'
That error message already says everything.该错误消息已经说明了一切。 Your problem arises because you are trying to to access
ctx.message.server.roles
when the correct syntax would be ctx.message.guild.roles
.出现您的问题是因为您尝试访问
ctx.message.server.roles
时正确的语法是ctx.message.guild.roles
。
I suggest you use the following code, as yours is pretty redundant:我建议您使用以下代码,因为您的代码非常多余:
@client.command()
async def play(ctx):
red_role = discord.utils.get(ctx.guild.roles, name="Red")
blue_role = discord.utils.get(ctx.guild.roles, name="Blue")
red_boss_role = discord.utils.get(ctx.guild.roles, name="Red Boss")
blue_boss_role = discord.utils.get(ctx.guild.roles, name="Blue Boss")
I believe your problem is you are using server
, as it is not defined, it is giving you an error AttributeError: 'Message' object has no attribute 'server'
and it states it is not an attribute of message.我相信你的问题是你正在使用
server
,因为它没有定义,它给你一个错误AttributeError: 'Message' object has no attribute 'server'
并且它声明它不是消息的属性。
red_role
and blue_role
both were using guild
, I've changed the ones below to guild, hopefully this works for you red_role
和blue_role
都在使用guild
,我已将下面的更改为 guild,希望这对你有用
@client.command()
async def play(ctx):
red_role = discord.utils.get(ctx.message.guild.roles, name="Red")
blue_role = discord.utils.get(ctx.message.guild.roles, name="Blue")
red_boss_role = discord.utils.get(ctx.message.guild.roles, name="Red Boss")
blue_boss_role = discord.utils.get(ctx.message.guild.roles, name="Blue Boss")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.