Команда выдачи роли абсолютно всем участникам сервера
Помогаю другу оформить и руководить его сервером. Мне необходимо написать команду, которая бы выдавала определенную роль всем участникам сервера в дискорд. Я полез с этим вопросом в документацию, но вообще ничего не понял. Решил обратится за помощью сюда.
import json
from flask import Flask, request, make_response, jsonify
from geopy.geocoders import Nominatim
import requests
from discord.ext import commands
from discord.utils import get
from config import settings
api_key = "buba"
base_url = "http://api.openweathermap.org/data/2.5/weather?"
bot = commands.Bot(command_prefix = settings['prefix'])
@bot.command()
async def hello(ctx):
author = ctx.message.author
await ctx.send(f'Hello, {author.mention}!')
@bot.command()
async def pat(ctx):
response = requests.get('https://some-random-api.ml/animu/pat')
json_data = json.loads(response.text)
embed = discord.Embed(color = 0x1f3151, title = 'Random pat')
embed.set_image(url = json_data['link'])
await ctx.send(embed = embed)
@bot.command()
async def hug(ctx):
response = requests.get('https://some-random-api.ml/animu/hug')
json_data = json.loads(response.text)
embed = discord.Embed(color = 0x1f3151, title = 'Random hug')
embed.set_image(url = json_data['link'])
await ctx.send(embed = embed)
@bot.command()
async def wink(ctx):
response = requests.get('https://some-random-api.ml/animu/wink')
json_data = json.loads(response.text)
embed = discord.Embed(color = 0x1f3151, title = 'Random wink')
embed.set_image(url = json_data['link'])
await ctx.send(embed = embed)
@bot.command()
async def weather(ctx, *, city: str):
city_name = city
complete_url = base_url + "appid=" + api_key + "&q=" + city_name
response = requests.get(complete_url)
x = response.json()
channel = ctx.message.channel
if x["cod"] != "404":
async with channel.typing():
y = x["main"]
current_temperature = y["temp"]
current_temperature_celsiuis = str(round(current_temperature - 273.15))
current_pressure = y["pressure"]
current_humidity = y["humidity"]
z = x["weather"]
weather_description = z[0]["description"]
weather_description = z[0]["description"]
embed = discord.Embed(title=f"Погода в городе: {city_name}",
color=ctx.guild.me.top_role.color,
timestamp=ctx.message.created_at,)
embed.add_field(name="Статус:", value=f"**{weather_description}**", inline=False)
embed.add_field(name="Температура(C)", value=f"**{current_temperature_celsiuis}°C**", inline=False)
embed.add_field(name="Влажность(%)", value=f"**{current_humidity}%**", inline=False)
embed.add_field(name="Давление(hPa)", value=f"**{current_pressure}hPa**", inline=False)
embed.set_thumbnail(url="https://i.ibb.co/CMrsxdX/weather.png")
embed.set_footer(text=f"Запрошено {ctx.author.name}")
await channel.send(embed=embed)
else:
await channel.send("Ты где живешь, еба*лак?")
bot.run(settings['token'])
Ответы (1 шт):
Автор решения: RAINGM
→ Ссылка
@bot.command()
async def add_role(ctx, role: discord.Role):
for member in ctx.guild.members:
await member.add_roles(role)
!add_role @role