我正在尝试制作一个能够分配静音角色的机器人。该机器人没有按照添加Muted角色的方式进行操作。总体而言,我的问题是1.为什么这不起作用? 2.如果不是小错误,正确的方法是什么?
我在Google上找到了多种用于静音的代码。我试图挑选一种可以直接实现我想要的功能的产品。我已经尝试了其他多个代码,但是对于它们的工作方式却感到困惑,没有进一步的解释。
import random
import asyncio
import aiohttp
import discord
import json
from discord.ext import commands
from discord import Game
from discord.ext.commands import Bot
import datetime
from discord.utils import get
import time
TOKEN = ''
client = discord.Client()
logdate = datetime.date.today()
happened = random.choice(["the users are.. speaking to me?", "the blasted humans are bothering my research", "the social interaction situation is going as planned"])
bot = Bot(command_prefix='?')
@client.event
async def on_ready():
print('According to my calculations I am ready to go!')
print(client.user.name)
print(client.user.id)
await client.change_presence(game=discord.Game(name="with Programs"))
print('------')
@bot.command(pass_context = True)
async def mute(ctx, member: discord.Member):
if ctx.message.author.server_permissions.administrator:
role = discord.utils.get(member.server.roles, name='Muted')
await bot.add_roles(member, role)
embed=discord.Embed(title="User Muted!", description="**{0}** was muted by **{1}**!".format(member, ctx.message.author), color=0xff00f6)
await bot.say(embed=embed)
await bot.process_commands(message) #added but doesn't change anything?
else:
embed=discord.Embed(title="Permission Denied.", description="You don't have permission to use this command.", color=0xff00f6)
await bot.say(embed=embed)
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
global logdate
global happened
if message.author == client.user:
return
elif message.content.startswith('Entrapta'):
msg = "Log date {}, it seems {}".format(logdate, happened, message)
await client.send_message(message.channel, msg)
client.run("")
我希望目标玩家获得静音角色,但是,当我尝试对@(person)静音时,什么也没发生。我在py.exe中没有收到错误消息,并且目标对象上没有出现任何Muted角色。实际上,我的代码格式正确,与上面代码所示不同。我在传输代码时遇到了麻烦。
由于重复而进行编辑:我的问题在@ bot.command中。它定义了静音而不是on_message。即使使用“重复”线程中的新代码部分,也没有添加任何更改。什么都没发生。我没有错误,也没有静音标签出现。我在上面添加了新代码。我在@ client.event中的事件运行正常。