Here’s the code
JavaScript
x
13
13
1
import discord
2
import random
3
from discord.ext import commands, tasks
4
from discord.utils import get
5
6
@client.command()
7
async def play(ctx):
8
red_role = discord.utils.get(ctx.message.guild.roles, name="Red")
9
blue_role = discord.utils.get(ctx.message.guild.roles, name="Blue")
10
11
red_boss_role = discord.utils.get(ctx.message.server.roles, name="Red Boss")
12
blue_boss_role = discord.utils.get(ctx.message.server.roles, name="Blue Boss")
13
and then DMing
JavaScript
1
5
1
for i in red_boss_role_id.members:
2
await i.send("🔴" + str(red_agents))
3
for i in blue_boss_role_id.members:
4
await i.send("🔵" + str(blue_agents))
5
I have already tried same thing with IDs, but no progress It says the error
JavaScript
1
2
1
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Message' object has no attribute 'server'
2
Advertisement
Answer
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.
red_role
and blue_role
both were using guild
, I’ve changed the ones below to guild, hopefully this works for you
JavaScript
1
8
1
@client.command()
2
async def play(ctx):
3
red_role = discord.utils.get(ctx.message.guild.roles, name="Red")
4
blue_role = discord.utils.get(ctx.message.guild.roles, name="Blue")
5
6
red_boss_role = discord.utils.get(ctx.message.guild.roles, name="Red Boss")
7
blue_boss_role = discord.utils.get(ctx.message.guild.roles, name="Blue Boss")
8