commands = {"привет": "Здравствуй!", "пока": "До свидания!"}
def send_msg(peer_id: int, message: str, attachment: str = None):
return vk.method("messages.send", {**locals(), "random_id": 0})
def main():
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
send_msg(
event.obj.peer_id,
commands.get(event.obj.text.lower(), "Я не знаю такой команды")
)
if __name__ == "__main__":
main()
params = {'group_id': 98446009, "sort": "id_desc", "offset": i, "fields": "online, sex", 'access_token': good_token, 'v': '5.103'}
members = requests.post('https://api.vk.com/method/groups.getMembers', data=params, headers=headers)
print(members.json())
fields
должны быть перечислены через запятую import discord
from discord.ext import commands
client = commands.Bot(command_prefix='!')
cycles = dict(test1=True)
@client.command(pass_context=True)
async def stop(ctx):
cycles["test1"] = False
@client.command(pass_context=True)
async def test1(ctx):
while cycles["test1"]:
await ctx.send('Test')
client.run ("TOKEN")
from threading import Thread
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='!')
@bot.command(pass_context=True)
async def f(ctx):
for i in range(3):
await ctx.send('Test2')
@bot.command(pass_context=True)
async def f_2(ctx):
for i in range(3):
await ctx.send('Test')
@bot.command(pass_context=True)
async def test1(ctx):
bot.loop.create_task(f(ctx))
bot.loop.create_task(f_2(ctx))
bot.run()
def get_members(peer_id: int):
return vk.method("messages.getConversationMembers", {
"peer_id": peer_id
})
if event.object.text.lower() == "онлайн":
members = [
f"[id{i['id']}|{i['first_name']} {i['last_name']}]"
for i in get_members(event.object.peer_id)["profiles"]
if i["online"] == 1
]
vk.method("messages.send", {
"peer_id": event.obj.peer_id,
"random_id": 0,
"message": "Сейчас в сети: {}".format(
"\n".join(members)
)
})
def get_members(peer_id: int) -> list:
return vk.method("messages.getConversationMembers", {
"peer_id": peer_id
})["items"]
def get_admins(peer_id: int) -> list:
return [
i["member_id"] for i in get_members(peer_id)
if i.get("is_admin", False)
]
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.text.lower() == "any_command":
if event.obj.from_id in get_admins(event.obj.peer_id):
do_something()
longpoll = VkBotLongPoll(vk_session, idgrup)
def get_user(pattern: str) -> int:
if "[id" in pattern:
return int(pattern.split("|")[0].replace("[id", ""))
if "vk.com/" in pattern:
domen = pattern.split("/")[-1]
return vk.users.get(user_ids=domen)[0]["id"]
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
text = event.obj["message"]["text"].split()
if (len(text) == 2) and text[0] == "кик":
try:
vk.messages.removeChatUser(
chat_id=event.chat_id,
member_id=get_user(text[1])
)
except Exception as e:
vk.messages.send(
chat_id=event.chat_id,
message="Произошла ошибка.",
random_id=0
)